Very good analysis of three simple Tab navigation (Web Tab)

Source: Internet
Author: User

The Application tab in a webpage makes the webpage more compact. Combined with AJAX technology, the webpage can display more content in a limited space. This article mainly introduces the implementation of several simple tab effects (not involving sliding doors and AJAX), with examples, no images, good compatibility, and easy to use.

The first form: it is implemented by changing the display style. This is very common and will not be said much.Copy codeThe Code is as follows: <div id = "tabs0">
<Ul class = "menu0" id = "menu0">
<Li onclick = "setTab (0, 0)" class = "hover"> News </li>
<Li onclick = "setTab (0, 1)"> comment </li>
<Li onclick = "setTab (0, 2)"> Technology </li>
<Li onclick = "setTab (0, 3)"> comments </li>
</Ul>
<Div class = "main" id = "main0">
<Ul class = "block"> <li> News list </li> </ul>
<Ul> <li> comment list </li> </ul>
<Ul> <li> Technology list </li> </ul>
<Ul> <li> comment list </li> </ul>
</Div>
</Div>

The second form: this structure is more complex, and a relative layer (. menu1box), set overflow to hide, set the tab (# menu1) to absolute positioning, and set the layer pointer to 1 (z-index: 1;) to cover the main block (. main1box) 1px height. Set the border of the main block to a black edge of 1px and the margin (margin-top) to-1px to extend the upper border to the tab. When the background of a tab item (li) is changed to white, the upper border of some primary blocks can be covered. In this way, the effect is achieved.Copy codeThe Code is as follows: <div id = "tabs1">
<Div class = "menu1box">
<Ul id = "menu1">
<Li class = "hover" onmouseover = "setTab (1, 0)"> <a href = "#"> News </a> </li>
<Li onmouseover = "setTab (1, 1)"> <a href = "#"> comment </a> </li>
<Li onmouseover = "setTab (1, 2)"> <a href = "#"> Technology </a> </li>
<Li onmouseover = "setTab (1, 3)"> <a href = "#"> comments </a> </li>
</Ul>
</Div>
<Div class = "main1box">
<Div class = "main" id = "main1">
<Ul class = "block"> <li> News list </li> </ul>
<Ul> <li> comment list </li> </ul>
<Ul> <li> Technology list </li> </ul>
<Ul> <li> comment list </li> </ul>
</Div>
</Div>
</Div>

JS Code in the first and second forms:Copy codeThe Code is as follows: function setTab (m, n ){
Var tli = document. getElementById ("menu" + m). getElementsByTagName ("li");/* obtain the LI object of the tab */
Var mli = document. getElementById ("main" + m). getElementsByTagName ("ul");/* Get the primary display area object */
For (I = 0; I <tli. length; I ++ ){
Tli [I]. className = I = n? "Hover": "";/* change the style of the LI object on the tab. Use the. hover style if selected */
Mli [I]. style. display = I = n? "Block": "none";/* determines which object is displayed in the main area */
}
}

The third form: this is also an uncommon way to add a relative layer (. menu2box), uses a background layer (# tip2) to locate, and changes the left distance (left) of the layer to achieve the effect.Copy codeThe Code is as follows: <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 = "#"> comment </a> </li>
<Li onmouseover = "nowtab (2, 2)"> <a href = "#"> Technology </a> </li>
<Li onmouseover = "nowtab (2, 3)"> <a href = "#"> comments </a> </li>
</Ul>
</Div>
<Div class = "main" id = "main2">
News content
</Div>
</Div>

Xmlns = "http://www.w3.org/1999/xhtml">


  • News
  • Comment
  • Technology
  • Comments
  • News list
  • Comment list
  • Technology list
  • Comment list

  • News
  • Comment
  • Technology
  • Comments
  • News list
  • Comment list
  • Technology list
  • Comment list

  • News
  • Comment
  • Technology
  • Comments
News content

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.