CSS Tabs Rollover Menu

Written by , Published On 11th July 2007.
Filed in Articles, CSS, Navigation.

Using a tabbed rollover menu in the header of your website can add functionality, as well as making the navigation look good. Doing this in CSS means that you can use it to it’s greatest capacity, easily add or remove tabs and change the colour in different styles.

Tab Header

1. Decide on the Navigational Elements and Colours

It is initially important to decide on which tabs you will want to place on your site, and what the colour scheme will be. You need to have an idea of how many tabs there will be, and what the default background and rollover background colour will be. Make a note of these!

2. How It Works

The tab area is set as a layer, to hover over a specific part of the page – you set this manually, based on where you would like it to be located.

Simply take the CSS code (see below), and change the commented values to fit in with the colour scheme of your website. You can go deeper and change elements such as the height, width and position of the menu bar if you want.

3. Download the CSS Code

Download a copy of the CSS code, then link to it as explained below.

4. Insert the CSS file into your HTML Code

Upload the tabsample.css file to your server, then place the following line in your area to link to the stylesheet.

1
<link rel="stylesheet" type="text/css" href="tabsample.css" />

5. Place the Tabs in your HTML Code

OK, so you’ve got all the formatting done for tabs in the CSS file, now you just need to place the correct HTML code in your index.php page.

For each tab you want to display, enter:

1
2
3
4
5
6
<ul id="supernav">
<li<?php if ($page=="home") { echo " id="selected""; } else {} ?>>
   <a href="/index.php" title="The Weblog">Blog</a>
</li>
-- Repeat as necessary for other tabs --
</ul>

For each different tab, change the following:

"home" – this is a one word description of the page (for the reason why, see below)
"/index.php" – this is the link to that particular page
"The Weblog" – a description of the page you’re linking to
Blog – the word you want to appear in your navigation bar as a link

Note: It doesn’t really matter where you place this source code, as the position they appear in is set in the CSS file. I would recommend somewhere near the header area.

6. What’s the PHP for?

The PHP code in the above line allows you to have an alternative look and feel for the tab on the current page (see the ‘Blog’ tab above?) Simply place this line underneath the tag of each page of your website:</p> <div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1 </pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;"><?php</span> <span style="color: #000088;">$page</span><span style="color: #339933;">=</span><span style="color: #0000ff;">"home"</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?></span></pre></td></tr></table></div> <p>As before, change <code>"home"</code> section to match that on the tab area.</p> <p>If you do not want to use this functionality or are not using PHP in your pages, replace the code in Step 5 with the following:</p> <div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1 </pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;"><<span style="color: #000000; font-weight: bold;">li</span>><<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"/index.php"</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"The Weblog"</span>></span>Blog<span style="color: #009900;"><<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>><<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>></span></pre></td></tr></table></div> <p>You should end up with a menu looking similar to the one at the top of this page in no time. It’s a simple method, and spices up your pages navigation!</p> <!-- Quick Adsense WordPress Plugin: http://techmilieu.com/quick-adsense --> <div style="float:none;margin:10px 0 10px 0;text-align:center;"> <script type="text/javascript"><!-- google_ad_client = "ca-pub-0222895541289977"; /* Mid-Post Ad */ google_ad_slot = "0806617728"; google_ad_width = 336; google_ad_height = 280; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> <div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div> </div> <div class="clear"></div> <div class="social_links"> <div class="reddit_btn"> <script src="http://www.stumbleupon.com/hostedbadge.php?s=1"></script> </div> <div class="tweetmeme_btn"> <a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> </div> <div class="tweetmeme_btn"> <g:plusone size="medium"></g:plusone> </div> <div class="tweetmeme_btn"> <a href="http://pinterest.com/pin/create/button/?url=http://designshack.net/articles/css-tabs-rollover-menu&media=&description=CSS Tabs Rollover Menu" class="pin-it-button" count-layout="horizontal">Pin It</a> <script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script> </div> <div class="facebook_btn"> <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like layout="button_count" show_faces="false" width="450"></fb:like> </div> </div> <div class="clear"></div> <div style="background:#e1e8dd; padding:20px;"> <!-- You can start editing here. --> <h1 class="commenttitle" id="comments">Discussion</h1> <ol class="commentlist"> <li class="comment even thread-even depth-1" id="comment-48"> <div id="div-comment-48" class="comment-body"> <div class="comment-author vcard"> <img alt='' src='http://0.gravatar.com/avatar/85f24cd322385382531ebb5158a6f5f5?s=75&d=http%3A%2F%2Fdesignshack.net%2Fwp-includes%2Fimages%2Fblank.gif&r=G' class='avatar avatar-75 photo' height='75' width='75' /> <cite class="fn"><a href='http://apexvideo.blogspot.com' rel='external nofollow' class='url'>shaid</a></cite> <span class="says">says:</span> </div> <div class="comment-meta commentmetadata"><a href="http://designshack.net/articles/css-tabs-rollover-menu/#comment-48"> September 26, 2007 at 1:37 pm</a> </div> <p>All excellent! nicely elaborate!!! CaR</p> <div class="reply"> </div> </div> </li> <li class="comment odd alt thread-odd thread-alt depth-1" id="comment-49"> <div id="div-comment-49" class="comment-body"> <div class="comment-author vcard"> <img alt='' src='http://0.gravatar.com/avatar/c8c44ba38095249ecfbff0df666ba9e0?s=75&d=http%3A%2F%2Fdesignshack.net%2Fwp-includes%2Fimages%2Fblank.gif&r=G' class='avatar avatar-75 photo' height='75' width='75' /> <cite class="fn"><a href='http://www.3wshare.com' rel='external nofollow' class='url'>Feng</a></cite> <span class="says">says:</span> </div> <div class="comment-meta commentmetadata"><a href="http://designshack.net/articles/css-tabs-rollover-menu/#comment-49"> September 30, 2007 at 1:21 pm</a> </div> <p>Green color is more popular now.. i find it looks like Digg navigation</p> <div class="reply"> </div> </div> </li> <li class="comment even thread-even depth-1" id="comment-57"> <div id="div-comment-57" class="comment-body"> <div class="comment-author vcard"> <img alt='' src='http://1.gravatar.com/avatar/135baacb32b4d332d8199564d1fa0bd4?s=75&d=http%3A%2F%2Fdesignshack.net%2Fwp-includes%2Fimages%2Fblank.gif&r=G' class='avatar avatar-75 photo' height='75' width='75' /> <cite class="fn"><a href='http://www.joomlabased.com' rel='external nofollow' class='url'>joomlabased</a></cite> <span class="says">says:</span> </div> <div class="comment-meta commentmetadata"><a href="http://designshack.net/articles/css-tabs-rollover-menu/#comment-57"> January 4, 2008 at 3:45 pm</a> </div> <p>Good tutorials. thank you</p> <div class="reply"> </div> </div> </li> <li class="comment odd alt thread-odd thread-alt depth-1" id="comment-80"> <div id="div-comment-80" class="comment-body"> <div class="comment-author vcard"> <img alt='' src='http://0.gravatar.com/avatar/245d324873978771f349fb32c1ff2299?s=75&d=http%3A%2F%2Fdesignshack.net%2Fwp-includes%2Fimages%2Fblank.gif&r=G' class='avatar avatar-75 photo' height='75' width='75' /> <cite class="fn">n0ta</cite> <span class="says">says:</span> </div> <div class="comment-meta commentmetadata"><a href="http://designshack.net/articles/css-tabs-rollover-menu/#comment-80"> April 5, 2008 at 5:08 pm</a> </div> <p>Hi man.</p> <p>I just arrive here from a stumble jump, and I want to add something.</p> <p>First of all, good tutorial and good easy use of php.</p> <p>But what I want to share is that there is a more easy, no server-side solution for that problem, only using CSS.</p> <p>It´s quite easy. You have only to put an “id” attribute to the tabs markup, and to use a “id” in the “body” tag. Smthg like:<br /> …</p> <p> Home<br /> Portfolio<br /> …</p> <p>And after that, it´s pretty simple. Just add a css line to change the tab you want when the page you visit is the appropiate. How does it know where it is? Easy, the body “id”. So…</p> <p>/*In the CSS */</p> <p>body#home a#menu_home {/*And put the effects to make it different*/}</p> <p>Same for others sections…</p> <p>Voilá. It´s done.</p> <div class="reply"> </div> </div> </li> <li class="comment even thread-even depth-1" id="comment-39805"> <div id="div-comment-39805" class="comment-body"> <div class="comment-author vcard"> <img alt='' src='http://0.gravatar.com/avatar/ee5dc49e64b40ae3213e3954517097ab?s=75&d=http%3A%2F%2Fdesignshack.net%2Fwp-includes%2Fimages%2Fblank.gif&r=G' class='avatar avatar-75 photo' height='75' width='75' /> <cite class="fn"><a href='http://www.howtowin-lottery.info/' rel='external nofollow' class='url'>"silver lotto,system,lottery,win,gambling,numbers,649,6/49,florida,texas,canadian,california,UK lottery,australian,software,silver-lotto,results</a></cite> <span class="says">says:</span> </div> <div class="comment-meta commentmetadata"><a href="http://designshack.net/articles/css-tabs-rollover-menu/#comment-39805"> November 27, 2011 at 7:38 pm</a> </div> <p>Excellent issues altogether, you just received a new reader. What could you recommend about your put up that you made a few days in the past? Any positive?</p> <div class="reply"> </div> </div> </li> <li class="comment odd alt thread-odd thread-alt depth-1" id="comment-40732"> <div id="div-comment-40732" class="comment-body"> <div class="comment-author vcard"> <img alt='' src='http://0.gravatar.com/avatar/c5fabe3849873d2b9a9b155d7244c86b?s=75&d=http%3A%2F%2Fdesignshack.net%2Fwp-includes%2Fimages%2Fblank.gif&r=G' class='avatar avatar-75 photo' height='75' width='75' /> <cite class="fn"><a href='http://npmw.ru' rel='external nofollow' class='url'>заработок в интернете</a></cite> <span class="says">says:</span> </div> <div class="comment-meta commentmetadata"><a href="http://designshack.net/articles/css-tabs-rollover-menu/#comment-40732"> December 27, 2011 at 12:21 pm</a> </div> <p>great post, very informative. I ponder why the opposite specialists of this sector do not understand this. You should proceed your writing. I am sure, you’ve a great readers’ base already!</p> <div class="reply"> </div> </div> </li> <li class="comment even thread-even depth-1" id="comment-41736"> <div id="div-comment-41736" class="comment-body"> <div class="comment-author vcard"> <img alt='' src='http://1.gravatar.com/avatar/31a657b71bdab067c31fe11f3f0fe2f9?s=75&d=http%3A%2F%2Fdesignshack.net%2Fwp-includes%2Fimages%2Fblank.gif&r=G' class='avatar avatar-75 photo' height='75' width='75' /> <cite class="fn"><a href='http://www.facebook.com/businessinformation' rel='external nofollow' class='url'>Business objects tutorial</a></cite> <span class="says">says:</span> </div> <div class="comment-meta commentmetadata"><a href="http://designshack.net/articles/css-tabs-rollover-menu/#comment-41736"> February 9, 2012 at 6:38 pm</a> </div> <p>Brand new content notifications : do you wish to be notified whenever a fresh article is actually added to the organization : marketing and advertising immediate category<a href="http://www.facebook.com/businessinformation" rel="nofollow">business</a></p> <div class="reply"> </div> </div> </li> </ol> <div class="navigation"> <div class="alignleft"></div> <div class="alignright"></div> </div> <div id="respond"> <h3>Leave Your Reply</h3> <div class="cancel-comment-reply"> <small><a rel="nofollow" id="cancel-comment-reply-link" href="/articles/css-tabs-rollover-menu#respond" style="display:none;">Click here to cancel reply.</a></small> </div> <form action="http://designshack.net/wp-comments-post.php" method="post" id="commentform"> <p><input type="text" class="text" name="author" id="author" value="" size="22" tabindex="1" aria-required='true' /> <label for="author"><small>Name (required)</small></label></p> <p><input type="text" class="text" name="email" id="email" value="" size="22" tabindex="2" aria-required='true' /> <label for="email"><small>Email (required)</small></label></p> <p><input class="text" type="text" name="url" id="url" value="" size="22" tabindex="3" /> <label for="url"><small>Website</small></label></p> <!--<p><small><strong>XHTML:</strong> You can use these tags: <code><a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight=""> </code></small></p>--> <p><textarea name="comment" id="comment" rows="6" tabindex="4"></textarea><label for="comment"><small class="message">Message</small></label></p> <button class="button" tabindex="5">Post Comment</button> <input type='hidden' name='comment_post_ID' value='482' id='comment_post_ID' /> <input type='hidden' name='comment_parent' id='comment_parent' value='0' /> </p> <p style="display: none;"><input type="hidden" id="akismet_comment_nonce" name="akismet_comment_nonce" value="dd8e7f3b73" /></p> </form> </div> </div> </div> <div class="clear"></div> </div> </div> </div> <div id="footer"> <div id="footer-content"> <div id="footer-about"> <h2><a href="/about/">About</a></h2> <p>Design Shack showcases inspiring web design, alongside resources and tutorials for you to succeed in the same way.</p> <img src="/images/josh.jpg" class="staffimage" /><p><a href="http://twitter.com/secondfret">Josh Johnson</a> is our writer and editor, taking care of the awesome content we publish!</p> <img src="/images/joel.jpg" class="staffimage" /><p><a href="http://twitter.com/#!/joel_bankhead">Joel Bankhead</a> is in charge of our gallery, carefully curating every new design.</p> <img src="/images/david.jpg" class="staffimage" /><p><a href="http://www.davidappleyard.net">David Appleyard</a> heads up management of the site, strategy, and advertising.</p> <div class="clear"></div> </div> <div id="footer-consultancy"> <h2><a href="/advice">Design Guidance & Advice</a></h2> <ul id="gallery_tabs"> <li><a href="/advice" class="current" id="loadcritique">Critique</a></li> <li><a href="/advice" id="loadanalysis">Analysis</a></li> <li><a href="/advice" id="loadbespoke">Bespoke</a></li> </ul> <div class="clear"></div> <div id="consultancy_content_area"> <div id="consultancy_container_critique"> <div class="price"> <span>$49</span> <div class="price_enquire"><a href="http://www.formstack.com/forms/designshack-design_guidance__advice">Order</a></div> </div> <p><strong>A Design Critique gives you the opportunity to have the Design Shack team analyse your site.</strong> We'll tell you what we like, and what we feel could be improved. This is published as an article on Design Shack to give you plenty of exposure (<a href="http://designshack.net/articles/critique-articles/web-design-critique-66-matthew-coughlin/">see an example</a>).</p> <a href="/consultancy" id="loadanalysis_2" style="margin:0 0 0 350px;"><img src="/images/right.png" alt="Right" /></a> </div> <div id="consultancy_container_analysis"> <div class="price"> <span>$499</span> <div class="price_enquire"><a href="http://www.formstack.com/forms/designshack-design_guidance__advice">Enquire</a></div> </div> <p><strong>With a Design Analysis, we produce an personal, in-depth report into every aspect of your website.</strong> It covers code, design, layout, semantics, SEO, and everything else, all provided in a beautiful printed report.</p> <a href="/consultancy" id="loadcritique_2"><img src="/images/left.png" alt="Left" /></a> <a href="/consultancy"id="loadbespoke_2" style="margin:0 0 0 310px;"><img src="/images/right.png" alt="Right" /></a> </div> <div id="consultancy_container_bespoke"> <div class="price"> <span>Price Varies</span> <div class="price_enquire"><a href="http://www.formstack.com/forms/designshack-design_guidance__advice">Enquire</a></div> </div> <p><strong>We can also offer advice and assistance with your whole design project, even managing the entire project for you.</strong> We'll work with selected partners in our amazing Design Shack community to produce a design that you love.</p> <a href="/consultancy" id="loadanalysis_3"><img src="/images/left.png" alt="Left" /></a> </div> </div> </div> <div id="footer-subscribe"> <h2><a href="http://feeds.feedburner.com/designshack">Subscribe</a></h2> <div class="socialicons"> <a href="http://twitter.com/designshack" class="twitter">Follow @designshack on Twitter</a> <a href="http://facebook.com/designshack" class="facebook">Like Design Shack on Facebook</a> <a href="https://plus.google.com/b/117605692722754678777/" class="googleplus">Find us on Google+</a> <a href="http://feeds.feedburner.com/designshack" class="rss">Subscribe to the Design Shack RSS Feed</a> <a href="/site/signup" class="email">Join our email newsletter</a> </div> <br /> <h2><a href="/about/">Our Partners</a></h2> <a href="http://www.smashingmagazine.com/" title="Part of the Smashing Network"> <img src="/images/smashingnetwork.png" alt="Part of the Smashing Network" /> </a> <a href="http://www.mediatemple.net/#a_aid=4e2dbbb0a0a4d" title="Professional Hosting by (mt)"> <img src="/images/mtlogo.png" alt="Professional Hosting by (mt)" style="margin: 10px 0 0 0;" /> </a> <p class="small">Copyright © Compact Creative Limited 2005-2012</p> </div> </div> </div> <div id="loginbox" style="display:none;"> <div id="loginbox_inner"> <form action="/login" method="post"> <label for="email">Email:</label> <input class="field" type="text" name="email" /><br /> <label for="password">Password:</label> <input class="field" type="password" name="password" /><br /> <div class="clear"></div> <div style="height:1px; width:100%; background-color: #fbfcfa; margin:0 0 15px 0;"></div> <button class="button">Login</button> </form> </div> </div> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-2121991-2"); pageTracker._trackPageview(); } catch(err) {}</script> <script type="text/javascript"> setTimeout(function(){var a=document.createElement("script"); var b=document.getElementsByTagName('script')[0]; a.src=document.location.protocol+"//dnn506yrbagrg.cloudfront.net/pages/scripts/0000/5990.js?"+Math.floor(new Date().getTime()/3600000); a.async=true;a.type="text/javascript";b.parentNode.insertBefore(a,b)}, 1); </script> </body> </html> <!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/ Minified using disk: basic Page Caching using disk: enhanced Object Caching 572/589 objects using disk: basic Served from: designshack.net @ 2012-02-10 04:52:32 -->