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

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:

Pretty, huh?
Next: Conclusion and All the Code >>
More Style Sheets Articles
More By Justin Cook
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|