Home arrow Style Sheets arrow Page 2 - Tabbed Browsing with CSS2
STYLE SHEETS

Tabbed Browsing with CSS2


So you've created one sweet web application, and you're very proud of the functionality, but the User Interface is somewhat lacking. Hey, don't worry, it happens to all of us. We are programmers after all, not UI designers! But don't despair; this tutorial will show you how to separate the pages of your application into ergonomically distinct chunks, by the use of CSS tabs. That's right, CSS, no tables involved!

Author Info:
By: Justin Cook
Rating: 4 stars4 stars4 stars4 stars4 stars / 19
July 28, 2004
TABLE OF CONTENTS:
  1. · Tabbed Browsing with CSS2
  2. · The Style
  3. · Conclusion and All the Code

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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?


blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...
- CSS3 Animated Image Gallery: Transitions
- CSS3 Properties: Fixed Heights with box-sizi...
- CSS3 Properties: Altering Strokes and 3D Eff...
- CSS3 Properties: Text-Stroke
- CSS3 Transitions: Width and Height Properties
- Creating a Drop Down Menu in CSS3
- Intro to CSS Transitions

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials