How to create a ribbon with CSS3 only
A Snapshot weekend project on November 2012
I like to add simple, subtle details to my design, and doing this using only CSS makes me happy :)
The Ribbon effect with CSS is very easy to obtain and took me few minutes to invent and code.
Have a look to the Demo Page
Here the basic HTML of the page, note that you can add the effect directly to the h2 element, I’ve wrapped it in a div element, just to have more control on the element’s padding and appearance:
Ribbon on the left
Ribbon side to side
The CSS code for the Ribbon aligned to the left:
.ribbon{
color: #fff;
margin: 30px 0 50px;
position: relative;
text-transform: uppercase;
background: rgb(0, 164, 239);
border: 1px solid rgba(0,0,0,.3);
box-shadow: 0px 1px 3px rgba(0,0,0,.2);
padding: 10px 15px;
clear: both;
}
div.left_ribbon{
color: #000;
margin-left: -10px;
float: left;
}
div.left_ribbon h2{
margin: 0 12px;
}
div.left_ribbon::before{
display: block;
width: 10px;
height: 0px;
position: absolute;
bottom: -10px;
left: -11px;
content: "";
border-bottom: 10px solid transparent;
border-right: 10px solid rgb(0, 80, 116);
}
div.left_ribbon::after{
display: block;
width: 6px;
height: 44px;
position: absolute;
bottom: 3px;
right: -1px;
content: "";
border: 1px solid rgba(0,0,0,.3);
transform: skew(0deg,45deg);
-ms-transform: skew(0deg,45deg); /* IE 9 */
-webkit-transform: skew(0deg,45deg); /* Safari and Chrome */
-o-transform: skew(0deg,45deg); /* Opera */
-moz-transform: skew(0deg,45deg); /* Firefox */
background: rgb(0, 80, 116);
}
and CSS code for the ribbon extended side to side
div.both_ribbon{
text-align: center;
color: #000;
padding: 10px 9px 10px 10px;
width: 100%;
margin-left: -10px;
}
div.both_ribbon::before{
display: block;
width: 10px;
height: 0px;
position: absolute;
bottom: -10px;
left: -11px;
content: "";
border-bottom: 10px solid transparent;
border-right: 10px solid rgb(0, 80, 116);
}
div.both_ribbon::after{
display: block;
width: 10px;
height: 0px;
position: absolute;
bottom: -10px;
right: -10px;
content: "";
border-bottom: 10px solid transparent;
border-left: 10px solid rgb(0, 80, 116);
}