Recently made a Web site to develop sentiment, want to write down some of the ideas in programming. In the process of doing the website want to do a tab navigation, just remember here. You are also welcome to visit my website.
Applying tabs in a Web page can make your pages more compact, and combining Ajax technology allows pages to show more content within a limited space. This article mainly introduces several simple tab effect implementation (not involving sliding doors and Ajax), with examples, no pictures, compatibility is good, convenient for everyone to use directly.
The first form: by changing the display style implementation, this is very common, not much to say.
CSS Code
- <div id="Tabs0" >
- <ul class="menu0" id="menu0" >
- <li onclick="Settab (0,0)" class="hover" > news </li>
- <li onclick="Settab (0,1)" > Comments </li>
- <li onclick="Settab (0,2)" > Technology </li>
- <li onclick="Settab (0,3)" > Reviews </li>
- </ul>
- <div class="main" id="Main0" >
- <ul class="block" ><li> News list </li></ul>
- <ul><li> Comments List </li></ul>
- <ul><li> Technology List </li></ul>
- <ul><li> Review List </li></ul>
- </div>
- </div>
Second form: This structure is more complex, outside with a relative layer (. menu1box), set overflow hiding, sets the tab (#menu1) to absolute positioning, set the layer pointer to 1 (z-index:1;), so that the height of the main chunk (. main1box) 1px can be obscured. Set the border of the main block to a black edge of 1px, and the upper space (margin-top) to -1px, so that the top frame is stretched to the tab. When you change the background of a tab item (LI) to white, you can mask the top border of a portion of the main block. This effect is achieved.
CSS Code
- <div id="TABS1" >
- <div class="Menu1box" >
- <ul id="menu1" >
- <li class="hover" onmouseover="Settab (1,0)" ><a href="#" > News </a></li>
- <li onmouseover="Settab" ><a href="#" > Comments </a></li>
- <li onmouseover="Settab" ><a href="#" > Technology </a></li>
- <li onmouseover="Settab (1,3)" ><a href="#" > Reviews </a></li>
- </ul>
- </div>
- <div class="Main1box" >
- <div class="main" id="main1" >
- <ul class="block" ><li> News list </li></ul>
- <ul><li> Comments List </li></ul>
- <ul><li> Technology List </li></ul>
- <ul><li> Review List </li></ul>
- </div>
- </div>
- </div>
The first to second type of JS code:
JS Code
- function Settab (m,n) {
- var Tli=document.getelementbyid ("menu" +m). getElementsByTagName ("Li"); / * Get the Li object for the tab * /
- var Mli=document.getelementbyid ("main" +m). getElementsByTagName ("ul"); / * Get the main display area object * /
- for (i=0;i<tli.length;i++) {
- Tli[i].classname=i==n? " hover": ""; / * Change the style of the Li object for the tab, or use the. Hover style if the item is selected * /
- Mli[i].style.display=i==n? " block":"None"; / * Determine which object is displayed in the main area * /
- }
- }
Third form: This is also an uncommon way to add a relative layer (. menu2box), using a background layer (#tip2) to locate the effect by changing the left side of the layer.
CSS Code
- <div id="TABS2" >
- <div class="Menu2box" >
- <div id="tip2" ></div>
- <ul id="MENU2" >
- <li class="hover" onmouseover="Nowtab (2,0)" ><a href="#" > News </a></li>
- <li onmouseover="Nowtab (2,1)" ><a href="#" > Comments </a></li>
- <li onmouseover="Nowtab (2,2)" ><a href="#" > Technology </a></li>
- <li onmouseover="nowtab (2,3)" ><a href="#" > Reviews </a></li>
- </ul>
- </div>
- <div class="main" id="main2" >
- News content
- </div>
- </div>