Style Sheets
  Home arrow Style Sheets arrow Page 2 - Tabbed Browsing with CSS2
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

Tabbed Browsing with CSS2
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 17
    2004-07-28

    Table of Contents:
  • Tabbed Browsing with CSS2
  • The Style
  • Conclusion and All the Code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Tabbed Browsing with CSS2 - The Style


    (Page 2 of 3 )

    Because we're using DIVs, which by default have a 'block' display, the output so far will look like this (assuming you have the icons in place):

    cook

    Not quite tabs. But now let's add a little style! Don't forget of course to add in the style declaration above the tab output coding!

    <style>
    #navTabs {
    font-family: verdana;
    padding: 0px 0px 0px 15px;
    margin: 0px;
    width: 100%;
    height: 30px;
    vertical-align: middle;
    border-color: #333333;
    border-style: solid;
    border-width: 0px 0px 2px 0px;
    }

    So here we've set up the initial style of the tab bar, with the height, width, and font. The two most important declarations are the left padding to set an initial little indentation, and the bottom border of 2 pixels.

    .tabon, .taboff {
    height: 30px;
    cursor: pointer;
    cursor: hand;
    display: inline;
    overflow: hidden;
    vertical-align: middle;
    font-size: 11px;
    padding: 6px 2px 0px 2px;
    margin: 0px 2px;
    border-color: #333333;
    border-style: solid;
    border-width: 1px 1px 0px 1px;
    }

    These are the common styles for both kinds of tabs. The cursor is set to emulate a link, the margin is set to separate each tab apart by a couple of pixels, and the borders are set. Very important is the changing of the display to 'inline', which enables them all to peacefully coexist on the same line, side-by-side. The vertical-align attribute doesn't really work as you or I would expect, so instead I employ the use of top padding to bump the image and text down closer to the middle of the tab.

    .taboff {
    color: #666666;
    background: #dddddd;
    }

    Here we make the inactive tabs look inactive. We make the font a little more faint, and the background gray.

    .tabOn {
    font-weight: bold;
    position: relative;
    top: 2px;
    background: #ffffff;
    border-width: 2px 2px 0px 2px;
    }

    And this is the magic that makes a tab 'active'. We make the font bold to stand out, the border a bit thicker, and then move it down 2 pixels to give the illusion that it's flowing into to the border, and it's attached to the bottom part of the screen. Make sure you set the background color, otherwise you'll still see the bottom border, and the illusion won't really work.

    After all is said and done, Here's what the finished product should look like:

    cook

    Pretty, huh?

    More Style Sheets Articles
    More By Justin Cook


       · Here is the PHP verison of the original ASP code. Note, this version is just as...
       · <?php $arTabs[] = array(); $arTabs[0] = "msds"; $arTabs[1] = "diagrams"; ...
       · The tabs don't display too well in firefox (v0.9). Any idea of a fix?
       · This doesn't work on Safari,IE5 and Firefox 0.8 on Mac OS X
       · The php section should be like this:<?php $arTabs[] = array(); $arTabs[0] =...
       · yes, that is a more efficient way of using basename...shoulda looked it up...the css...
       · This also doesn't work in Mozilla 1.7.1.Has anyone found any solutions to...
       · I have found a solution all, thanks to teh excellent Paul O'Brian. Include the...
       · $thisPage = basename($_SERVER[PHP_SELF], ".php");This line works nicely too. And...
       · Please help. Thanks.
       · How useful, please help you with what? Your hairstyle? Your failed social life?
       · where will i put <a href=""> on every tab...??tnx..
       · You do not use href as the javascript takes care of switching...
     

    STYLE SHEETS ARTICLES

    - Image Replacement CSS Techniques
    - Using BlueTrip`s Success, Notice and Error C...
    - More Uses for the Thin and Caps CSS Classes ...
    - Styling Definition Lists with the BlueTrip C...
    - Styling Unordered and Ordered HTML Lists wit...
    - Using the BlueTrip CSS Framework`s Thin and ...
    - Adding Borders to Web Page Columns with Blue...
    - Introducing the BlueTrip CSS Framework
    - Using a Background Grid to Assist Web Page L...
    - Extending the Rule Of Thirds for Web Page La...
    - A Two-Column Web Page Layout Based on the Ru...
    - Using the Rule Of Thirds for Web Page Layout
    - Swapping Columns Using the Divine Ratio for ...
    - Using the Golden Ratio in Liquid Web Page De...
    - Fundamental Design Principles for Web Page L...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek