Get $500+ of the best After Effects files, video templates and music for only $20!
How to Create a Modern Ribbon Banner Navigation Bar with Pure HTML/CSS3

How to Create a Modern Ribbon Banner Navigation Bar with Pure HTML/CSS3

Tutorial Details
  • Code Languages: HTML / CSS3
  • Difficulty: Intermediate
  • Estimated Time: 20 mins

Final Product What You'll Be Creating

As CSS3 becomes more robust and is more widely supported, the options for fun modern design elements that can be created without graphics are virtually limitless! For a recent project, I decided to see if I could create a centered ribbon banner with pure CSS3. This tutorial will walk you through how it was done.

As it turns out, it’s actually quite easy, using only simple, semantic HTML and some CSS3 trickery thanks to the magic of the the border-width property. The only caveat: As with all new CSS3 techniques, it can act a bit wonky in some IE browsers… we’ll address that at the end of the tutorial.

Here’s how:


Step 01: The Navigation Links

We want to create a navigation link bar, so we’re going to begin with a simple unordered list [ul] with links inside [a]. This is one of the most basic building blocks of markup; good for creating lists of elements to be styled in a similar way like we’re going to do here:

The code:



We want the links to float horizontally across the page, so we’ll add the following styles:

First, we want to remove the bullet styling from the list-items, and make them float to the left of each other, and add a bit of space between them.

#navigation li {
        list-style: none;
        display: block;
        float: left;
        margin: 1em;
}

Next, we’ll add a bit of text-shadow, remove the link underlines, and add the text color and size.

#navigation li a {
        text-shadow: 0 2px 1px rgba(0,0,0,0.5);
        display: block;
        text-decoration: none;
        color: #f0f0f0;
        font-size: 1.6em;
        margin: 0 .5em;
}

I also like to add a bit of soft animation effects on hover:

#navigation li a:hover {
        margin-top: 2px;
}

To add the stars, I’ve placed an HTML entity ✭ inside of each link. This is purely decorative, and not needed for the functionality.

At this point, we already have a nice usable navigation link section that we could add into a page. But we’re going to keep going to create a nice ribbon to put these links inside of.


Step 02: The Ribbon Banner

The border-width technique that we’re going to use does require that we add 4 extra elements to the markup. While it’s not ideal to add extraneous elements, in the long-run it’s probably still more efficient than loading up extra graphics, and we’ll keep things as simple as possible.

First, we’ll create a container element around the links. This will allow us to set a width to keep all the banner elements together:


We’ll add the following style to set the width and center the container element:

#navigation_container {
   margin: 0 auto;
   width: 960px;
}

Next, we’ll add the rectangle that will be the body section of the ribbon:

We’ll add the following styles to create the ribbon body background. We’re setting a z-index of 500 because the rectangle needs to be stacked on top of the triangles that we’ll create next. I’m adding both -moz-box-shadow and box-shadow to account for Firefox and -webkit/IE9 respectively:

.rectangle {
   background: #e5592e;
   height: 62px;
   position: relative;
   -moz-box-shadow: 0px 0px 4px rgba(0,0,0,0.55);
   box-shadow: 0px 0px 4px rgba(0,0,0,0.55);
   -webkit-border-radius: 3px;
   -moz-border-radius: 3px;
   border-radius: 3px;
   z-index: 500; /* the stack order: foreground */
   margin: 3em 0;
}

Next, we’ll add the triangles to the edges of the ribbon:


Finally, we’ll add some border-width magic. The key to this is setting a border-color of transparent for each side of the element except for the bottom (for the top triangles) and top (for the bottom triangles). Then, we set a border-width of 50px. This creates an isosceles triangle, which we will then position behind the main body of the ribbon:

.l-triangle-top {
   border-color: #d9542b transparent transparent;
   border-style:solid;
   border-width:50px;
   height:0px;
   width:0px;
   position: relative;
   float: left;
   top: 1px;
   left: -50px;
}

.l-triangle-bottom {
   border-color: transparent transparent #d9542b;
   border-style:solid;
   border-width:50px;
   height:0px;
   width:0px;
   position: relative;
   float: left;
   top: -40px;
   left: -150px;
}

We’ll do the same for the right side:

.r-triangle-top {
   border-color: #d9542b transparent transparent;
   border-style:solid;
   border-width:50px;
   height:0px;
   width:0px;
   position: relative;
   float: right;
   right: -45px;
   top: -107px;
}

.r-triangle-bottom {
   border-color: transparent transparent #d9542b;
   border-style:solid;
   border-width:50px;
   height:0px;
   width:0px;
   position: relative;
   float: right;
   top: -149px;
   right: -145px;
}

And we’re done! This will render perfectly in Firefox and Webkit browsers. IE is notoriously bad at using these CSS3 properties, so it won’t render perfectly there, but we’ll do our best to get it pretty close using a couple custom stylesheets.

For IE8 and IE9, we’ll add some custom positioning rules through the “ie.css” stylesheet:

.l-triangle-top {
	left: 150px;
	top: 50px;
}
.l-triangle-bottom {
	left: 50px;
	top: -12px;
}
.r-triangle-top {}
.r-triangle-bottom {
	top: -169px;
}

Just to be on the safe side (and since we believe in progressive enhancement), we’ll also add a fix for IE7, which can be placed in either the head section of your page or in a separate IE7 stylesheet. My choice of a fix is to simply hide the triangles in browsers lower than IE8. The browser-width property is supported in IE7, but the spacing will be a bit off. It’s up to you whether you’d like to spend the extra time re-positioning the elements in IE7:



Wrapping It Up

The background images are just for fun – you can add your own and build around this document… or just grab everything above this and drop it into your own design. But, in the interest of being comprehensive, here’s the CSS that’s adding in those images:

html{
background: #77d5fb url('bottom_bg.jpg') bottom center no-repeat;
}

body{
background: transparent url('top_bg.png') top center no-repeat;
width: 100%;
height: 100%;
margin: 0 0;
}

Credits: The images are from iStockPhoto – we can’t distribute the bottom island image with the demo, but you can grab it for yourself here.


That’s It!

Hope you guys enjoyed this one! Remember that this is a fairly new set of techniques… so if your goal is 100% stability on all browsers known to man, there are more stable ways of accomplishing this using basic images for the background. Leave your comments and questions below ;)

Read More about creating a ribbon or folding effect:

  • Create a 3D Ribbon Wrap-Around Effect (Plus a Free PSD!)

    I thought it might be fun to create a tutorial on the popular 3d Wrap-Around Ribbon effect that has been popping up so much this year. This is a great way to add depth to your designs, and it’s pretty darn easy to complete.

    Visit the Post

  • Quick Tip: Practical CSS Shapes

    A common design technique lately is to create a fold effect, where it appears as if a heading is wrapping behind its container. This is generally achieved through the use of tiny images; however, with CSS, we can mimic this effect quite easily. I’ll show you how in four minutes.

    Visit the Post

Add Comment

Discussion 30 Comments

  1. Nice, i recently made a site using a similar ‘ribbon banner navigation bar’ i used an image here:
    http://bit.ly/hKyzmR, but this is a good alternative.

    Daniel

  2. Derrick W. Thompson says:

    This is an amazing article! I have been having a hard time creating modern ribbon banners, but your step by step process makes it easy. Thanks for breaking this down and I look forward to future tutorials.

    Derrick Thompson

  3. Wow very cool little effect. I did this once with images, its just always so much cooler if its pure css and html. Great tutorial thanks!

  4. Programming CSS and HTML navigation bars have always been very difficult for me. Now I completely understand what I need to accomplish in order to built awesome navigation bars.

  5. Moon Themes says:

    Very nice and fancy ribbon banner, even more i like the background image, can you please tell me where did you get that background image from? i would like to have one too!

    And thanks for sharing this tutorial.

  6. Brian says:

    Wow, I didn’t even know you could do that. Thanks for sharing!

    Curious, would this work for the ribbon effect using only one div for the right side fork effect instead of two?

    border-color: #D9542B transparent #D9542B #D9542B;

  7. Very good although it did not work on my htc desire which could be a problem

  8. Moksha says:

    awesome doing this without photoshop is just great. thanks

  9. Ben Stokoe says:

    Good job, but if you make the viewer small than the banner, the left ‘folded back’ bit of the banner cannot be seen.

  10. Pablo Mendoza says:

    I like this, CSS ribbon :D

  11. Wouter J says:

    Why wouldn’t you use :before and :after. That makes the HTML code much better.

  12. Kien Nguyen says:

    I made it. Nice tut and very easy to follow. Thanks!

  13. Jatin says:

    Just 3 words for this tutorial: Awesome and Brilliant.

  14. mark says:

    Didn’t realise that this could be done. Great tutorial

  15. Jake says:

    You can use the :before and :after pseudo elements in the css so that you don’t need to make individual triangles. Instead use the :before element to replace the four triangles:

    .rectangle:before {
    content: “heyyy”; /* creates an object that can be manipulated */
    color: transparent;
    font-size: 0px; /* make the text invisible */
    position: absolute;
    margin-top: 3px;
    margin-left: -50px;
    width: 938px;
    height: 0px;
    border-color: #d9542c transparent; /* creates the triangles using the top and bottom borders */
    border-style: solid;
    border-width: 29px;
    z-index: -999; /* keep the ribbon from covering the text */
    }

    Then, because the browser doesn’t place the ribbon container’s shadow above the :before element, we have to re-add the box-shadow and the lighter color of red to the ribbon:

    .rectangle:after {
    content: ” “;
    background: #E5592E;
    position: absolute;
    height: 100%;
    width: 100%;
    -moz-box-shadow: 0px 0px 4px rgba(0,0,0,0.55);
    -webkit-box-shadow: 0px 0px 4px rgba(0,0,0,0.55);
    box-shadow: 0px 0px 4px rgba(0,0,0,0.55);
    -webkit-border-radius: 2px;
    -moz-border-radius: 2px;
    border-radius: 2px;
    z-index: -999;
    }

    This is my first time commenting, so I hope this makes some sense….?

  16. sawebdesigns says:

    thanks for sharing this awesome tutorial

  17. Devin Walker says:

    I’m a bit of a markup snob, but I’d prefer to use an image-based approach rather than having empty DIVs and incompatibility issues.

  18. Palestinian 4 Ever says:

    Nice Job man

    And You can also Make 3d Prepective shadow to add some hard details

    in Pesudo – Element (Before – After)

  19. reezluv says:

    great CSS tips. Now I am really understand why CSS is much more important..it can do anything..lol..

  20. Well explained tutorial. Your tutorial is excellent and quite in derived oriented for everybody who are in the field of designing especially. You did great job in form of tutorial and inspirational thought or message to designers.

  21. Kopepasah says:

    Although I find it quite spectacular that we are given the ability to create awesome designs with pure CSS3, the unnecessary use of the div merely pushes us back to the old ages of web design.. In my opinion, images are better to use with clean HTML.

  22. Ryan says:

    I would like to see a tutorial on how to create the illustration in the sample (the island / mountain / ocean).

  23. Endy says:

    thanks man…u make my navigation looks great…
    and i just want to add a little css for make it looks better…
    anyway..thanks..

  24. Jason says:

    Thanks for the great tutorial. I love how this comes out.

    However, Im having problems making the ribbon work with Internet Explorer. It works fine with all other browsers. Any tips from anyone would be appreciated. http://www.sdindependentplumbing.com/

    Thanks in advance.

  25. Malick E says:

    How on earth do I add a background colour change on hover?! Whenever I do it, it ends up being the same size as the text instead of filling the entire list item.
    Anyone know the fix?
    Thanks.

  26. lee says:

    Good tut, but the codes are too long, and too complex, though its effect is so nice, maybe use the background images will be a bit easy.

  27. Dan says:

    When I tried the tutorial it all looked great, except that my content further down the page was getting pushed around by the right hand side triangles.

  28. Gabriel says:

    I followed this great tutorial and everything worked just fine. I thought I might share a bit of work I did, related to ribbons….the holiday season is still a long way away, but I thought it can’t hurt to share some of the festive ribbons I designed last X-mas.. enjoy and use them well. http://www.creattor.com/vectors/christmas-ribbon-banners-4010

Add a Comment