I have the following gold dividing line I'm trying to create in pure CSS.
I'm trying to create this with the transform:scale; CSS So far I have found the following:
.border_angle {
border: 50vw solid transparent;
width: 0;
height: 0;
border-bottom-color: transparent;
border-left-color: transparent;
border-top-color: transparent;
transform: scaleY(0.105) translateY(-50%);
-webkit-transform: scaleY(0.105) translateY(-50%);
-o-transform: scaleY(0.105) translateY(-50%);
-moz-transform: scaleY(0.105) translateY(-50%);
-ms-transform: scaleY(0.105) translateY(-50%);
position: absolute;
transform-origin: top center;
top: 0;
left: 0;
right: 0;
z-index: 11;
}
.border_angle_gold_l {
border-left-color: #BE955A;
}
.border_angle_gold-light_r {
border-right-color: #CCA56B;
}
<div style="margin-top: 200px;" class="border_angle border_angle_gold_l border_angle_gold-light_r"></div>
Essentially, I nearly have it but I just need to reverse the triangles!! I can't figure out how... Any help would be massively appreciated.
I would do this differently with less of code and linear-gradient:
.triangle {
margin-top:100px;
height:80px;
background-image:
linear-gradient(to bottom right, transparent 50%,#BE955A 51%),
linear-gradient(to top right, transparent 50%,#BE955A 51%),
linear-gradient(to bottom left, transparent 50%,#CCA56B 51%),
linear-gradient(to top left, transparent 50%,#CCA56B 51%);
background-position:0 0,0 100%,100% 0,100% 100%;
background-size:50.3% 50%;
background-repeat:no-repeat;
}
<div class="triangle">
</div>
Here is another idea using clip-path:
.triangle {
margin-top: 100px;
height: 80px;
background: linear-gradient(to left, #CCA56B 50%, #BE955A 0);
-webkit-clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
<div class="triangle">
</div>
You could try duplicating the div and then adding translateX like:
.border_angle {
border: 50vw solid transparent;
width: 0;
height: 0;
border-bottom-color: transparent;
border-left-color: transparent;
border-top-color: transparent;
position: absolute;
transform-origin: top center;
top: 0;
left: 0;
right: 0;
z-index: 11;
}
.border_angle_gold_l {
border-left-color: #BE955A;
}
.border_angle_gold-light_r {
border-right-color: #CCA56B;
}
.first {
transform: scaleY(0.105) translateY(-50%) translateX(50%);
-webkit-transform: scaleY(0.105) translateY(-50%) translateX(50%);
-o-transform: scaleY(0.105) translateY(-50%) translateX(50%);
-moz-transform: scaleY(0.105) translateY(-50%) translateX(50%);
-ms-transform: scaleY(0.105) translateY(-50%) translateX(50%);
}
.second {
transform: scaleY(0.105) translateY(-50%) translateX(-50%);
-webkit-transform: scaleY(0.105) translateY(-50%) translateX(-50%);
-o-transform: scaleY(0.105) translateY(-50%) translateX(-50%);
-moz-transform: scaleY(0.105) translateY(-50%) translateX(-50%);
-ms-transform: scaleY(0.105) translateY(-50%) translateX(-50%);
}
<div style="margin-top: 200px;" class="border_angle border_angle_gold_l border_angle_gold-light_r first"></div>
<div style="margin-top: 200px;" class="border_angle border_angle_gold_l border_angle_gold-light_r second"></div>
Just to complete the other good answers:
The pseudo element / border approach
You can create the triangles with the help of borders and apply it to the pseudo elements ::before and ::after of your divider. This reduces your code, you only need one element in your markup and you don't have to use transformations:
.divider {
position: relative;
width: 500px;
}
.divider::before,
.divider::after {
content: '';
position: absolute;
width: 0;
height: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
}
.divider::before {
border-right: 250px solid #bf9655;
left: 0;
}
.divider::after {
border-left: 250px solid #cda667;
right: 0;
}
<div class="divider"></div>
The SVG approach
As SVG is widely supported now, it is also reasonable to use SVG to create shapes. Here would be a simple example, reducing the code length to a minimum of 141B:
<svg viewbox="0 0 24 2">
<polygon points="0,1 12,0 12,2" style="fill:#bf9655;" />
<polygon points="12,0 24,1 12,2" style="fill:#cda667;" />
</svg>
Related
How to hide a curve tail of bubble chat box while different background color using css ?
body {
background: #1e5799;
background: -moz-linear-gradient(-45deg, #1e5799 0%, #2989d8 50%, #2989d8 50%, #7db9e8 100%);
background: -webkit-linear-gradient(-45deg, #1e5799 0%,#2989d8 50%,#2989d8 50%,#7db9e8 100%);
background: linear-gradient(135deg, #1e5799 0%,#2989d8 50%,#2989d8 50%,#7db9e8 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=1 );
}
.speech-bubble {
position: relative;
background: #ddd;
border-radius: .4em .4em .4em 0;
width: 100px;
padding: 30px 15px;
margin:auto;
text-align: center;
color: white;
font-weight: bold;
font-size: 200%;
text-shadow: 0 -0.05em 0.1em rgba(0,0,0,.3);
}
.speech-bubble:before {
content: "";
position: absolute;
z-index: -1;
bottom: -30px;
right: 100%;
height: 30px;
border-right: 25px solid #ddd;
*background: #00aabb;
-webkit-border-bottom-right-radius: 80px 50px;
-moz-border-radius-bottomright: 80px 50px;
border-bottom-right-radius: 80px 50px;
-webkit-transform: translate(0, -2px);
-moz-transform: translate(0, -2px);
-ms-transform: translate(0, -2px);
-o-transform: translate(0, -2px);
transform: rotate(-181deg) translate(-35%, 97%);
}
/* creates part of the curved pointy bit */
.speech-bubble:after {
content: "";
position: absolute;
z-index: -1;
bottom: -30px;
right: 100%;
width: 21px;
height: 30px;
background: #fff;
-webkit-border-bottom-right-radius: 40px 50px;
-moz-border-radius-bottomright: 40px 50px;
border-bottom-right-radius: 40px 50px;
-webkit-transform: translate(-30px, -2px);
-moz-transform: translate(-30px, -2px);
-ms-transform: translate(-30px, -2px);
-o-transform: translate(-30px, -2px);
transform: rotate(0deg) translate(0%, -97%);
}
<div class="speech-bubble"></div>
Honestly, the best way is to use photo shop and alter the image. You can maybe find a css Hack involving having a div with position and z-index sitting on top of the white corner...but that will be an ugly solution to a simple problem. Just find a better image or alter it yourself in photoshop or the like.
Just change it's background color to match the one of the body element:
:root {
--bgc: #ece8e8; /* defined background color */
}
body {
background: var(--bgc); /* used here */
}
.speech-bubble {
position: relative;
background: #ddd;
border-radius: .4em;
width: 100px;
padding: 30px 15px;
margin: auto;
text-align: center;
color: white;
font-weight: bold;
font-size: 200%;
text-shadow: 0 -0.05em 0.1em rgba(0,0,0,.3);
}
.speech-bubble:before {
content: "";
position: absolute;
z-index: -1;
bottom: -30px;
right: 100%;
height: 30px;
border-right: 25px solid #ddd;
*background: #00aabb;
-webkit-border-bottom-right-radius: 80px 50px;
-moz-border-radius-bottomright: 80px 50px;
border-bottom-right-radius: 80px 50px;
-webkit-transform: translate(0, -2px);
-moz-transform: translate(0, -2px);
-ms-transform: translate(0, -2px);
-o-transform: translate(0, -2px);
transform: rotate(-181deg) translate(-35%, 97%);
}
/* creates part of the curved pointy bit */
.speech-bubble:after {
content: "";
position: absolute;
z-index: -1;
bottom: -30px;
right: 100%;
width: 21px;
height: 30px;
background: var(--bgc); /* and here */
-webkit-border-bottom-right-radius: 40px 50px;
-moz-border-radius-bottomright: 40px 50px;
border-bottom-right-radius: 40px 50px;
-webkit-transform: translate(-30px, -2px);
-moz-transform: translate(-30px, -2px);
-ms-transform: translate(-30px, -2px);
-o-transform: translate(-30px, -2px);
transform: rotate(0deg) translate(0%, -97%);
}
<div class="speech-bubble"></div>
Preferably done with CSS Variables to make it dynamic so that you don't have to check if the two match or change it twice, while you can do it once on the :root element and be sure.
I'm creating a down arrow for the bottom of a full width div, which works great in the one instance below (where a coloured section runs into a white section):
But not for this instance...
The situation above has a blue div with a down arrow going into a full width background image. As you can see it doesn't quite work.
I want the tip of the arrow to lay over the top of the image... or another colour. How can I do that?
Here's my setup:
<div class="bannerStripHeader" style="background-color:#009edb;">
<section class="row">
<div class="columns large-12" style="color:inherit !important;">
<div class="brandHeaderContent">
Content here
</div>
</div>
</section>
</div>
I'm using the border colour to set it to white.
.bannerStripHeader:before {
border-width: 50px 0 30px 70vw;
border-color: transparent transparent transparent #fff;
left: -5px;
-webkit-transform: rotateZ(0deg);
transform: rotateZ(0deg);
-webkit-transform-origin: 100% 50%;
-ms-transform-origin: 100% 50%;
transform-origin: 100% 50%;
}
.bannerStripHeader:after {
border-width: 50px 70vw 30px 0;
border-color: transparent #fff transparent transparent;
right: -5px;
-webkit-transform: rotateZ(0deg);
transform: rotateZ(0deg);
-webkit-transform-origin: 0 50%;
-ms-transform-origin: 0 50%;
transform-origin: 0 50%;
}
.bannerStripHeader:after,
.bannerStripHeader:before {
content: "";
border-style: solid;
bottom: -23px;
height: 0;
-webkit-transition: -webkit-transform .5s ease .5s;
transition: transform .5s ease .5s;
width: 0;
position: absolute;
}
The description and the code you provided don't really match well so I'm not quite sure what you're asking. Are you trying to achieve something like this demo?
.bannerStripHeader {
position: absolute;
overflow: hidden;
}
.bannerStripHeader:before {
border-width: 50px 50vw 0 50vw;
border-color: #009edb transparent transparent transparent;
left: 50%;
transform: translate(-50%, 0);
top: 0;
width: 0;
height: 0;
display: block;
content: "";
border-style: solid;
position: absolute;
}
/* only for demo */
img {
width: 100%;
}
<div class="bannerStripHeader">
<section class="row">
<div class="columns large-12">
<div class="brandHeaderContent">
<img src="https://images.unsplash.com/photo-1427477321886-abc24e8ce923?dpr=1&auto=compress,format&fit=crop&w=1199&h=800&q=80&cs=tinysrgb&crop=">
</div>
</div>
</section>
</div>
I am working on a project where I want to create a diagonal div using CSS like in this image:
You can use the css "clip path". It's pretty simple to understand.
#shape {
-webkit-clip-path: polygon(0 55%, 100% 0%, 100% 100%, 0% 100%);
clip-path: polygon(0 55%, 100% 0%, 100% 100%, 0% 100%);
width:200px;
height:200px;
background-color:black;
}
<div id='shape'></div>
.myDiv {
width: 400px;
height: 400px;
border: 1px solid #000;
background-image: url('https://pbs.twimg.com/profile_images/739247958340698114/fVKY9fOv.jpg');
position: absolute;
overflow: hidden;
}
.myDiv:after {
content: '';
position: absolute;
z-index: 4;
width: 0;
height: 0;
border-bottom: 800px solid red;
border-left: 800px solid transparent;
top: -40%;
left: -50%;
-ms-transform: rotate(30deg); /* IE 9 */
-webkit-transform: rotate(30deg); /* Chrome, Safari, Opera */
transform: rotate(30deg);
}
p {
position: relative;
top: 70%;
z-index: 5;
font-size: 35px;
text-align: center;
}
<div class="myDiv">
<p>Hello World!</p>
</div>
Using Bootstrap and Transition Skew CSS Property https://jsfiddle.net/oocputgz/24/
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="blog-post-image">
<img src="https://i.imgsafe.org/20ff17cabf.jpg" class="img-responsive center-block" />
</div>
<div class="post-detail_container">
<div class="sperator"></div>
<div class="post-content">
<h3 class="post-title">
Hello World
</h3>
</div>
</div>
</div>
</div>
</div>
CSS Styling:
.post-detail_container
{
position:relative;
}
#blog-items .item
{
padding:0px 15px;
}
.sperator
{
position: absolute;
top: 0;
width: 100%;
height: 100px;
-webkit-transform-origin: 0 0;
-moz-transform-origin: 0 0;
-ms-transform-origin: 0 0;
-o-transform-origin: 0 0;
transform-origin: 0 0;
-webkit-transform: skew(0, -7deg);
-moz-transform: skew(0, -7deg);
-ms-transform: skew(0, -7deg);
-o-transform: skew(0, -7deg);
transform: skew(0, -7deg);
background: red;
}
.post-content
{
background-color:red;
padding:15px 15px;
min-height: 300px;
}
.post-title
{
font-size: 40px;
line-height: 24px;
margin-bottom: 2px;
color: #fff;
text-align: center;
margin-top: 88px;
}
I would like to make a diamond shape with a image background. I can do it, the only problem is the image seems to rotate at the same time which i do not want. This also needs to work in ie8
fiddle:http://jsfiddle.net/zangief007/2bft2rcx/1/
#diamond {
width: 80px;
height: 80px;
background: purple;
margin: 3px 0 0 30px;
/* Rotate */
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
/* Rotate Origin */
-webkit-transform-origin: 0 100%;
-moz-transform-origin: 0 100%;
-ms-transform-origin: 0 100%;
-o-transform-origin: 0 100%;
transform-origin: 0 100%;
}
Try removing the rotation and adding
#diamond:before, #diamond:after{
content: '';
border: 80px solid transparent;
position: absolute;
top: 50%;
margin-top: -80px;
z-index: -1;
}
#diamond:before {
border-right-color: #ccc;
border-left: none;
right: 50%;
}
#diamond:after {
border-left-color: #ccc;
border-right: none;
left: 50%;
}
Demo
How can I deactivate the top DIV so that I can select what's under it?
Check what I did here:
http://jsfiddle.net/zE5Ze/2/
#triangle_w {
width: 1000px;
height: 178px;
overflow: hidden;
position: fixed;
left: -24px;
top: -82px;
/*outline: 1px solid pink;*/
-moz-transform: rotate(-10deg);
-webkit-transform: rotate(-10deg);
}
#triangle {
width: 961px;
height: 176px;
background: url('http://i.imgur.com/FTGa2.png') no-repeat;
position: absolute;
left: 10px;
bottom: -80px;
/*outline: 1px solid red;*/
-moz-transform: rotate(10deg);
-webkit-transform: rotate(10deg);
}
#triangle #menu {
-moz-transform: rotate(-10deg);
-webkit-transform: rotate(-10deg);
/*outline: 1px solid red;*/
}
Without the rotation: http://jsfiddle.net/zE5Ze/5/
As you can see, the areas inside the red outline are not selectable.
Is there a way to do this without having to fiddle with CSS rotations?
I'd like to deactivate the triangle, and leave only the menu and the thumbs active.
Simple. Give a z-index.
#triangle #menu a {z-index: 5;}
Fiddle: http://jsfiddle.net/zE5Ze/3/
Or set a width!
#triangle_w {width: 100px;}
Fiddle: http://jsfiddle.net/zE5Ze/4/