Xah Lee, 2006-02
This page shows you how to implement Tab Menu using CSS.
Click on the tab on top of this page. You can see that pages get switched and the corresponding tab gets highlighted. Here's how this is done in pure CSS.
Let's say you want a tab menu for 3 pages, A, B, and C. Put this into the top of page A:
<ul id="pageA" class="tabs"> <li id="a"><a href="a.html">Tab A</a></li> <li id="b"><a href="b.html">Tab B</a></li> <li id="c"><a href="c.html">Tab C</a></li> </ul>
Similarly, put them into page B and C but use “id="pageB"” and “id="pageC"”.
Then, all you have to do is use the style sheet to control how your tab should look. Notice that in the above code there's “id="pageA"”. So, in your style sheet, you just specify how tag that match “pageA” will look. Like this:
#pageA #a {background-color:red} #pageA #b {background-color:silver} #pageA #c {background-color:silver} #pageB #a {background-color:silver} #pageB #b {background-color:red} #pageB #c {background-color:silver} #pageC #a {background-color:silver} #pageC #b {background-color:silver} #pageC #c {background-color:red}
View the source code of this page for detail.
Related essays: