CSS Tabs Rollover Menu

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.

<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:

<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> <pre class="brush: php; title: ; notranslate" title=""> <?php $page="home"; ?> </pre> <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> <pre class="brush: xml; title: ; notranslate" title=""> <li><a href="/index.php" title="The Weblog">Blog</a></li> </pre> <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> </article> <aside> <section class="social-share sticky-social"> <h3>Share This Post</h3> <div class="social-links"> <a href="https://twitter.com/intent/tweet?text=CSS+Tabs+Rollover+Menu&url=https://designshack.net/articles/css-tabs-rollover-menu/&via=designshack" class="icon-twitter" title="Share on Twitter"><span>Share on Twitter</span></a> <a href="https://www.facebook.com/sharer/sharer.php?u=https://designshack.net/articles/css-tabs-rollover-menu/" class="icon-facebook" title="Share on Facebook"><span>Share on Facebook</span></a> <a href="http://pinterest.com/pin/create/button/?url=https://designshack.net/articles/css-tabs-rollover-menu/&description=CSS+Tabs+Rollover+Menu&media=https://designshack.net/images/twitter-card.jpg" class="icon-pinterest" title="Share on Pinterest"><span>Share on Pinterest</span></a> </div> </section> </aside> </div> </div> </div> </main> <div class="wrapper wrapper-footer"> <footer> <div class="copyright-social"> <p><a href="https://compactcreative.com">Made by Compact Creative © 2024</a></p> <p class="social-links"> <a href="https://twitter.com/designshack" class="icon-twitter" title="@designshack on Twitter"><span>Twitter</span></a> <a href="https://facebook.com/designshack" class="icon-facebook" title="Facebook"><span>Facebook</span></a> <a href="https://www.pinterest.com/designshack/" title="Pinterest" class="icon-pinterest"><span>Pinterest</span></a> <a href="http://feedpress.me/designshack" title="RSS Feed" class="icon-rss"><span>RSS Feed</span></a> </p> </div> <div class="footer-links"> <p><strong><a href="https://designshack.net" title="Design Shack">Home</a></strong> / <strong><a href="https://designshack.net/category/articles/" title="Design Articles & Tutorials">Articles</a></strong> / <strong><a href="https://designshack.net/features/" title="Design Features">Features</a></strong> / <strong><a href="https://designshack.net/resources/" title="Design Resources">Resources</a></strong> / <strong><a href="https://designshack.net/design/" title="Design Gallery">Gallery</a></strong></p> <p><a href="https://designshack.net/about/" title="About Design Shack">About</a> / <a href="https://designshack.net/about/advertising/" title="Design Shack Advertising">Advertising & Sponsorship</a> / <a href="https://designshack.net/about/contact/" title="Contact Us">Contact</a> / <a href="https://designshack.net/about/privacy/" title="Privacy Policy">Privacy</a></div> <div class="kinsta-partnership"> <p><a class="kinsta-link" rel='nofollow' href="https://kinsta.com?kaid=YJUDYYWVXAPN"><span>In Partnership with</span></a></p> </div> </footer> </div> <script type="text/javascript" src="https://designshack.net/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shCore.js" id="syntaxhighlighter-core-js"></script> <script type="text/javascript" src="https://designshack.net/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shBrushPhp.js" id="syntaxhighlighter-brush-php-js"></script> <script type="text/javascript" src="https://designshack.net/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shBrushXml.js" id="syntaxhighlighter-brush-xml-js"></script> <script type='text/javascript'> (function(){ var corecss = document.createElement('link'); var themecss = document.createElement('link'); var corecssurl = "https://designshack.net/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shCore.css?ver=3.0.9b"; if ( corecss.setAttribute ) { corecss.setAttribute( "rel", "stylesheet" ); corecss.setAttribute( "type", "text/css" ); corecss.setAttribute( "href", corecssurl ); } else { corecss.rel = "stylesheet"; corecss.href = corecssurl; } document.head.appendChild( corecss ); var themecssurl = "https://designshack.net/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shThemeMidnight.css?ver=3.0.9b"; if ( themecss.setAttribute ) { themecss.setAttribute( "rel", "stylesheet" ); themecss.setAttribute( "type", "text/css" ); themecss.setAttribute( "href", themecssurl ); } else { themecss.rel = "stylesheet"; themecss.href = themecssurl; } document.head.appendChild( themecss ); })(); SyntaxHighlighter.config.strings.expandSource = '+ expand source'; SyntaxHighlighter.config.strings.help = '?'; SyntaxHighlighter.config.strings.alert = 'SyntaxHighlighter\n\n'; SyntaxHighlighter.config.strings.noBrush = 'Can\'t find brush for: '; SyntaxHighlighter.config.strings.brushNotHtmlScript = 'Brush wasn\'t configured for html-script option: '; SyntaxHighlighter.defaults['class-name'] = 'code-display'; SyntaxHighlighter.defaults['pad-line-numbers'] = true; SyntaxHighlighter.defaults['toolbar'] = false; SyntaxHighlighter.defaults['wrap-lines'] = false; SyntaxHighlighter.all(); // Infinite scroll support if ( typeof( jQuery ) !== 'undefined' ) { jQuery( function( $ ) { $( document.body ).on( 'post-load', function() { SyntaxHighlighter.highlight(); } ); } ); } </script> </body> </html>