Ribbon
<h1 class="ribbon">
<strong class="ribbon-content">Everybody loves ribbons</strong>
</h1>
.ribbon {
font-size: 16px !important;
/* This ribbon is based on a 16px font side and a 24px vertical rhythm. I've used em's to position each element for scalability. If you want to use a different font size you may have to play with the position of the ribbon elements */
width: 50%;
position: relative;
background: #ba89b6;
color: #fff;
text-align: center;
padding: 1em 2em; /* Adjust to suit */
margin: 2em auto 3em; /* Based on 24px vertical rhythm. 48px bottom margin - normally 24 but the ribbon 'graphics' take up 24px themselves so we double it. */
}
.ribbon:before, .ribbon:after {
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:after {
right: -2em;
border-left-width: 1.5em;
border-right-color: transparent;
}
.ribbon .ribbon-content:before, .ribbon .ribbon-content:after {
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;
}
.ribbon .ribbon-content:after {
right: 0;
border-width: 1em 1em 0 0;
}
Protector
This technique uses negative z-index values on some of the pseudo elements. That means that they can go behind other elements that have opaque backgrounds, which ruins the effect. To fix this, you'll need to make sure the immediate parent of the ribbons does not have a background applied and has relative postioning with positive z-index. Use an additional wrapper if needed.
<div class="non-semantic-protector">
<!-- ribbons and other content in here -->
</div>
.non-semantic-protector { position: relative; z-index: 1; }
Example
Everybody loves ribbons
Really interesting and clever technique.
The ribbon looks nice.
Thanks for sharing :)
good1… i personally dont know anyone who doesnt love ribbons :)
I hate ribbons . Never ever seen them done right. E.g. In this example, where’s the shadow cast by the ribbon?
improvise dude… the tutorial is to show you how to make a ribbon in CSS, not to trick it all out for you. Read into the abilities of the webkit because drop shadowing does not work in all browsers.
add this to your ribbon, it will work in Firefox.. Also, you can change the opacity by adjusting the alpha levels of in the hex.
-moz-box-shadow: 3px 3px 4px #999;
-webkit-box-shadow: 3px 3px 4px #999;
Next time don’t be so quick to run your mouth, this guy is doing all of us web designers a favor by making a nice place for us to reference while developing. Nobody is going to hold your hand while your learning all of these different languages so don’t be so quick to bad mouth the ones trying to help out in the first place.
I absolutly Love this!!
i was having a hard time doing this in photoshop the other week. and im glad there’s a css way too! it is quite a few lines of code. but thank you so much thinking of all this. you really do put a lot of time and effory in your tuts, and screen casts! im truly grateful for everything you’ve done Chris. Thank you
– Attila
Is there a way to make this work in IE 8 and below?
I’m running IE8 and the example here doesn’t work but James’ Reference URL works great…
http://jameskoster.co.uk/blog/pure-css-3d-ribbon/
I quickly compared the CSS but didn’t find anything different…but the solution is there somewhere.
I like this ribbon, sharp edges but the fact that it doesn’t use a graphic is somewhat inspiring. Thanks for sharing.
Wow, thanks for sharing, very interesting to know.. This is really great!
I love the use of the pseudo elements – can’t wait to try and thanks for sharing.
Thanks man,I love it!!
Thanks for sharing.
I’ve tried to do this a few times and wonder how it works in a nav menu as the bar.
Hi there,
Love this tutorial. Only thing I can’t figure out is how I can implement it with my wordpress menu?
The menu is build with the following code:
‘header’, ‘container’ => ” ) ); ?>
What I don’t understand is how I can create extra classes to add the css code to?
Greetings,
Jonas
Something went wrong with the presentation of the code. I’ve made a topic in the css forum about this.
Hope someone can help me out?
http://css-tricks.com/forums/discussion/13611/my-wordpress-menu-with-a-ribbon
Jonas Smets
this one works for adding class in wordpress menu
wp_nav_menu( array( ‘container_class’ => ‘menu-header’ etc
tried some other modification for a logo overlapping the ribbon (with navigation) somehow not working for other browser except for Firefox .(without css hacks)
I’m still working on a project with ribbon nav and this tutorial is really helpful.
Credits to the author!
Very cool, didn’t know I could do this in CSS.
But does anyone have a hack for this effect in IE8 and below? Because it isn’t working in those browsers, which means I can only use this on personal projects and not for anything else.
Using this trick to target IE8 and below that I found here:
http://net.tutsplus.com/tutorials/html-css-techniques/quick-tip-how-to-target-ie6-ie7-and-ie8-uniquely-with-4-characters/
I got rid of the borders that form the points of the ribbon:
border: 0\9; /* IE8 and below */
So now older versions of IE show a plain rectangle, instead of a dismembered pseudo-ribbon. The ribbon still displays as above in all other browsers. It may be boring, but at least it doesn’t look broken.
@Chrizzi That is very helpful, thanks! Good to know this effect can gracefully fall back. Sweet!
Really love this trick!
However I wonder how to create this type of ribbon using CSS:
http://img822.imageshack.us/img822/4185/ribboni.jpg
And could we automatically adjust the ribbon height so that I can type longer/shorter text content without even re-adjusting the css height parameter manually?
I believe the IE8 problem can’t be fixed, but one thing we can do is set up the ribon the other way, i.e. as if the sides were before the content, not behind.
You can achieve this by simply removing the z-index:-1; line, and replacing
border-color: #804f7c transparent transparent transparent;
bottom: -1em;
with
border-color: #804f7c transparent #804f7c transparent;
top:0;
in the .ribbon .ribbon-content:before, .ribbon .ribbon-content:after {…} declaration
You may also want to set top:1em; on .ribbon:before, .ribbon:after {…}
This way the things doesn’t break if your content goes on two lines
So how would I make a ribbon without the “folds”? I thought of doing a sidebar with a ribbon background for the active page’s link. Something like this shape:
http://www.photoshopstar.com/wp-content/uploads/2008/03/ribbon-filled-yellow.jpg
Or.. how would you make a ribbon with both sides with the same triangular cut?
I’d like to do this with list items, not divs, though. Any ideas?
take a look at jacklmoore site <a href=”http://www.jacklmoore.com/notes/css3-ribbon-menu title=”www.jacklmoore.com”>
That’s amazing…I was actually looking for it since two days…couldn’t figure it out with Photoshop..!!!
Thank You..!
Yes i think everybody love ribbon, including me. I wonder How to make this ribbon as a html menu? is it only use href? Thanks.
If you want to use it as an html menu, just embed a
<
ul> of your nav inside .ribbon-content.
Anyone else having issues with this in mobile? Specifically, the z-index seems to get ignored, bringing the ends of the banner above the main ribbon.
It works great on desktop browsers, but in chrome on my android phone, the corners are on top.
Thanks for providing this. I would like to modify this result, but do not understand how it works. A step by step commenting of the css and what each part of it does would be very helpful. Has anyone created those type of comments?
I’m especially confused about the ribbon:before, ribbon-content:before and :after lines in the CSS
thanks
Nice tutorial – I’ve actually created a similar walk-through on my site. However, my ribbon wraps around a box element and has a drop shadow as well. Uses the same :before and :after technique. http://www.designcouch.com/demos/pure-css-ribbon-banner.html