How do I draw the end of a ribbon like the left side of this image using only CSS?
I know I can use the fact that corners in CSS are mitered, so I can have a div
with a border of size 0 and other borders bigger to give me triangles. Is there a way to do this with only 1 div
? Or do I need to stack some triangles? I'd really prefer to have 1 div
so that users don't have to think about this and I can just use the CSS :before
pseudo element to insert this. What's the best way to implement this?
IE9+ and modern versions of other browsers only need to be supported.
HTML
<div class="ribbon">
<strong class="ribbon-content">Everybody loves ribbons</strong>
</div>
CSS
.ribbon {
font-size: 16px !important;
width: 50%;
position: relative;
background: #ba89b6;
color: #fff;
text-align: center;
padding: 1em 2em; /* Adjust to suit */
margin: 2em auto 3em;
}
.ribbon:before {
content: "";
position: absolute;
display: block;
bottom: -1em;
border: 1.5em solid #986794;
z-index: -1;
}
.ribbon:before {
left: -2em;
border-right-width: 1.5em;
border-left-color: transparent;
}
.ribbon .ribbon-content:before {
content: "";
position: absolute;
display: block;
border-style: solid;
border-color: #804f7c transparent transparent transparent;
bottom: -1em;
}
.ribbon .ribbon-content:before {
left: 0;
border-width: 1em 0 0 1em;
}
See Demo
Reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With