SpyreStudios

Web Design and Development Magazine

  • Design
  • Showcase
  • Inspirational
  • Tutorials
  • CSS
  • Resources
  • Tools
  • UX
  • More
    • Mobile
    • Usability
    • HTML5
    • Business
    • Freebies
    • Giveaway
    • About SpyreStudios
    • Advertise On SpyreStudios
    • Get In Touch With Us

How To Create a Sweet CSS3 Vertical Navigation

December 15, 2010 by Eric Hoffman 13 Comments

Today we’ll be creating a beautiful vertical CSS3 navigation, without the use of images. Basically we’ll display a circle with an icon in the center. When the user hovers over the circle, it expands and shows a short description.

Now you may be wondering: how are we going to display an icon without images? Well, Drew Wilson’s (fabulous) Pictos font makes this quite simple. Unfortunately (but understandably) it’s not free, you can purchase is for $49 here. Luckily, there are other icon fonts out there like iconic, which you can use for free.

I should also mention that this has been tested using Webkit browsers only (Safari, Chrome). It may work in other browsers but probably with limited support. Check out the demo here!

So, let’s get started!

HTML

As always, we’ll begin with the html. Paste the following code into your document.

[html]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Sweet CSS3 Vertical Navigation</title>
<link rel="stylesheet" type="text/css" href="reset.css"/>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>

</body>
</html>
[/html]

As you can see we’re using the new html5 doctype. Both the html and the meta charset tags been simplified vastly in the new doctype. You can combine both stylesheets into one, but I think having two separate documents is cleaner. If you use two, make sure the reset is listed first, so that your normal stylesheet can overwrite the default values specified in the reset.

Next add this code.

[html]
<div id="nav">
<a href="#" class="active"><span class="pictos">p</span><span class="hidden">My rants</span></a>
<a href="#"><span class="pictos">i</span><span class="hidden">All about me</span></a>
<a href="#"><span class="pictos">o</span><span class="hidden">My projects</span></a>
<a href="#"><span class="pictos">M</span><span class="hidden">Drop a line</span></a>
</div>
[/html]

We’re opening a div with the id nav, and placing four links inside. Inside each link, we have a span with the class pictos and a span with the class hidden. Inside the pictos span, we have a letter. Each letter and some symbols are equivalent to an icon in the pictos web font. The hidden span will not actually be hidden, instead it will have a large left margin, that hides it, as the overflow will be set to hidden. Inside the span you can add a short description of the icon displayed. E.g if the icon is a pencil, you can write ‘My blog‘ inside the second span. Make sure the first link has the class of active, meaning it’s wider than the others, hence it displays the description.

CSS

As with most navigation bars, you’ll find the larger part of the code inside the stylesheet.

First we’ll create a short reset sheet, to make sure all default values the browser has set back to 0. I normally use Eric Meyer’s css reset, but this one that jsFiddle uses should work just fine.

[html]
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td {
margin:0;
padding:0;
}

table {
border-collapse:collapse;
border-spacing:0;
}

fieldset,img {
border:0;
}

address,caption,cite,code,dfn,em,strong,th,var {
font-style:normal;
font-weight:normal;
}

ol,ul {
list-style:none;
}

caption,th {
text-align:left;
}

h1,h2,h3,h4,h5,h6 {
font-size:100%;
font-weight:normal;
}

q:before,q:after {
content:”;
}

abbr,acronym {
border:0;
}
[/html]

First we’ll style the entire document by adding 10px of padding and and a background color of #d1eaf9.

[html]
body {
background: #d1eaf9;
padding: 10px;
}
[/html]

Next we’ll ‘import’ the pictos font into the document by using @font-face. Luckily the pictos font comes with the necessary files and code, otherwise I use the FontSquirrel @font-face generator.

[html]
@font-face {
font-family: ‘Pictos’;
src: url(‘font/pictos-web.eot’);
src: local(‘☺’), url(‘font/pictos-web.woff’) format(‘woff’), url(‘font/pictos-web.ttf’) format(‘truetype’), url(‘font/pictos-web.svg’) format(‘svg’);
font-weight: normal;
font-style: normal;
}
[/html]

Now to the actual styling of the navigation:

[html]
#nav a {
display: block;
font-style: normal;
font-family: ‘Pictos’;
font-size: 20px;
padding: 2px 20px 38px 20px;
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0a324a), to(#08283b));
width: 20px;
text-decoration: none;
overflow: hidden;
text-shadow: 0 -1px 1px black;
border-radius: 50px;
color: white;
height: 20px;
margin-bottom: 10px;
border: 5px solid #146595;
-webkit-transition: all ease-in-out .3s;
-webkit-background-clip: padding-box;
}
[/html]

To be able to add width, height etc. we have to change the way the link displays to block.

Change the font-family to Pictos, and the font-size to 20px. For some reason, the pictos font has weird top-padding, meaning the top-padding on the link is less than the bottom padding.

Two apps helped me create the background gradient, the CSS3 gradient generator we created in a previous tutorial and 0to255, a sweet app to find variations of any color.

Remove any text-decoration, and very important, change the overflow to hidden. This hides the span with the description. Add a black text-shadow, a border-radius of 50px and a solid border of #146595. To ease the width-increase a little, change the -webkit-transition to all ease-in-out .3s. To remove the ugly background-bleed add -webkit-background-clip: padding-box to your code.

Next style the the span.hidden

[html]
#nav a span.hidden {
font-family: ‘Lucida Grande’;
font-size: 12px;
font-weight: bold;
margin-top: 2px;
margin-left: 40px;
}
[/html]

Set the font-family to Lucida Grande, or whatever nice-looking sans-serif typeface you like. 20px is a little too big for my taste, 12px looks a lot better. So does font-weight: bold. The pictos font and the description are not aligned correctly, that’s why we’ll add a 2px margin-top. And to hide the description from view, add a 40px left margin.

We’ll have to display the description when the user hovers over the button, meaning we change the width to 200px.

[html]
#nav a:hover, #nav a.active {
width: 200px;
}

#nav a:active {
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#08283b), to(#0a324a));
-webkit-box-shadow: inset 0 0 2px #222;
}
[/html]

Finally we’ll rotate the background gradient by 180 degrees in it’s active state, and add a box shadow of 2px with the color #222222.

Your Turn To Talk

Done! Great job!

You can view the demo right here →

Some of you have been asking why most of my tutorials only support webkit browsers. The answer is simple: Webkit browsers support most of the new ‘features‘ of HTML5 and CSS3, whereas Mozilla, Opera, etc… are still catching up. I’m sure it’s possible to achieve similar results in all browsers (except for IE6 of course), but it’d definitely require a lot more code.

As always, post your results in the comment section if you like. And feel free to ask questions too!

Filed Under: CSS, Development, HTML5, Tutorial

Comments

  1. Josh says

    December 15, 2010 at 9:16 pm

    Lame – it doesn’t work on Firefox. Not sure how this is a “sweet” vertical navigation when it doesn’t even work on modern browsers. What good is that? It’s not smart to not support a modern browser simply because it’s “catching up” with browsers that only about 15% of the internet population use.

    “Pretty” lost. Usability is King. Get with it.

  2. Jon Phillips says

    December 15, 2010 at 9:59 pm

    If someone says ‘Webkit only’ and it doesn’t work in your favorite non-Webkit browser, don’t blame the person that said it – there’s a lot that can be done with Webkit that a lot of browsers don’t support, should we stop experimenting because it doesn’t work in Firefox? This nav menu is not meant to be used in a production environment.

    The goal with this tutorial wasn’t to show people how to code this kind of navigation using 12 different methods (jQuery, CSS3, etc..) it was to show how it can be done with Webkit.

  3. Eric Hoffman says

    December 15, 2010 at 11:20 pm

    @Josh You are right to some extent, the navigation of a site should definitely work with all browsers, old and new. But as @Jon already said, this tutorial shows you how to create a quite good looking vertical navigation using only code – meaning it is image-less. It is not meant to replace your current navigation. Web designers and developers should explore new techniques and experiment with them, perhaps even implement them into their designs. And as I wrote (if you take the time to read it, or even skim through the tutorial), only webkit browsers support this navigation, so why do you try it in Firefox (note: it’s “in Firefox” and not “on Firefox”)? I’m sure some of these techniques, like a linear gradient, are supported in other browsers, like your beloved Firefox. That’s why I mentioned the CSS3 gradient generator we created last time (scroll up, you’ll see the link).

    OK? Great. For future reference, please think before you write :)

  4. idraki says

    December 16, 2010 at 2:08 am

    I guess you just can’t read when he says that it only tested and perhaps only work on -Webkit browser. What’s the use of usability when you can’t even read and understand. Read properly the content – is the KING. Get with it.

  5. Chris says

    December 16, 2010 at 3:19 am

    That’s such a cool nav! I love the slide out effect.

  6. Sarah Jones says

    December 16, 2010 at 5:19 am

    Creating vertical navigation have always been a big headache for me and my team. But I thankfully found this link. Thanks for this information. It was very much useful for us…

  7. DayTrans says

    December 16, 2010 at 6:07 am

    This is cool!

  8. Web Žurnál says

    December 16, 2010 at 9:44 am

    I looks cool, but the best is that its pretty fast!

  9. James says

    December 16, 2010 at 3:39 pm

    Thanks for the tutorial. I think people need to appreciate that just because CSS3 isn’t supported by all browsers yet, it shouldn’t stop us from experimenting. We’re in a transitional period, and old school designers that refuse to adopt new techniques that aren’t working 100% in all browsers will be left lagging behind. I’m not saying that you should implement a navigation that doesn’t work in Firefox, it’s about keeping your eyes open, and gaining inspiration from what others do.

  10. subrat sahu says

    December 17, 2010 at 6:10 am

    very useful tuto

  11. Inspirationfeed says

    December 18, 2010 at 5:41 pm

    Great tutorial mate!

  12. Josh says

    December 21, 2010 at 10:14 pm

    Eric, I did read the entire article. I tried it on Firefox (note: it’s “on Firefox, not “in Firefox because you, the user are not inside the browser, only viewing what is on it) because it’s a modern browser that there’s no excuse for something to not work nearly perfect on it. I know you said to view it with a webkit browser – and that’s fine. It looked really cool in Safari. Webkit browsers are definitely the leading edge when it comes to browser technology. I personally use all sorts of webkit and mozilla specific css3 properties when I’m developing websites – but I at least make sure that they fail gracefully.

    My main beef is that you didn’t specify that this was “just an example” of what is possible. I’m all for experiments. If you had included that one disclaimer, I wouldn’t have even commented. But what’s to stop the average Joe with a mac to run across this code, think it’s really cool and put it on his company’s website – only to make it completely unusable for people on most other browsers? That’s my problem.

  13. Ayo says

    January 10, 2011 at 2:51 am

    Inspiring.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please prove you're human *

Recent Posts

  • 31 Fresh Design Elements for Spring and Easter
  • 10 Templates for Music Concert Flyers
  • How to Build a Web Scraper Using Node.js
  • Best PHP Books, Courses and Tutorials in 2022
  • How to Get Your First Web Design Client

Archives

  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • May 2008
  • April 2008

Categories

  • Accessibility
  • Android
  • Apps
  • Art
  • Article
  • Blogging
  • Books
  • Bootstrap
  • Business
  • CSS
  • Design
  • Development
  • Ecommerce
  • Fireworks
  • Flash
  • Freebies
  • Freelance
  • General
  • Giveaway
  • Graphic Design
  • HTML5
  • Icons
  • Illustrator
  • InDesign
  • Infographics
  • Inspirational
  • Interview
  • Jobs
  • jQuery
  • Learning
  • Logos
  • Matrix
  • Minimalism
  • Mobile
  • Motion Graphics
  • Music
  • News
  • Photoshop
  • PHP
  • Promoted
  • Rails
  • Resources
  • Showcase
  • Tools
  • Tutorial
  • Twitter
  • Typography
  • Uncategorized
  • Usability
  • UX
  • Wallpapers
  • Wireframing
  • WordPress
  • Work

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

SpyreStudios © 2022