Analysis on three simple and classic tabs created by DIV + CSS, divcss

Source: Internet
Author: User

Analysis on three simple and classic tabs created by DIV + CSS, divcss

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.

Css code
  1. <Div id = "tabs0">
  2. <Ul class = "menu0" id = "menu0">
  3. <Li onclick = "setTab (0, 0)" class = "hover"> News </li>
  4. <Li onclick = "setTab (0, 1)"> comment </li>
  5. <Li onclick = "setTab (0, 2)"> Technology </li>
  6. <Li onclick = "setTab (0, 3)"> comments </li>
  7. </Ul>
  8. <Div class = "main" id = "main0">
  9. <Ul class = "block"> <li> News list </li> </ul>
  10. <Ul> <li> comment list </li> </ul>
  11. <Ul> <li> Technology list </li> </ul>
  12. <Ul> <li> comment list </li> </ul>
  13. </Div>
  14. </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.

Css code
  1. <Div id = "tabs1">
  2. <Div class = "menu1box">
  3. <Ul id = "menu1">
  4. <Li class = "hover" onmouseover = "setTab (1, 0)"> <a href = "#"> News </a> </li>
  5. <Li onmouseover = "setTab (1, 1)"> <a href = "#"> comment </a> </li>
  6. <Li onmouseover = "setTab (1, 2)"> <a href = "#"> Technology </a> </li>
  7. <Li onmouseover = "setTab (1, 3)"> <a href = "#"> comments </a> </li>
  8. </Ul>
  9. </Div>
  10. <Div class = "main1box">
  11. <Div class = "main" id = "main1">
  12. <Ul class = "block"> <li> News list </li> </ul>
  13. <Ul> <li> comment list </li> </ul>
  14. <Ul> <li> Technology list </li> </ul>
  15. <Ul> <li> comment list </li> </ul>
  16. </Div>
  17. </Div>
  18. </Div>


JS Code in the first and second forms:

Js Code
  1. Function setTab (m, n ){
  2. Var tli = document. getElementById ("menu" + m). getElementsByTagName ("li");/* obtain the LI object of the tab */
  3. Var mli = document. getElementById ("main" + m). getElementsByTagName ("ul");/* Get the primary display area object */
  4. For (I = 0; I <tli. length; I ++ ){
  5. Tli [I]. className = I = n? "Hover": "";/* change the style of the LI object on the tab. Use the. hover style if selected */
  6. Mli [I]. style. display = I = n? "Block": "none";/* determines which object is displayed in the main area */
  7. }
  8. }


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.

Css code
    1. <Div id = "tabs2">
    2. <Div class = "menu2box">
    3. <Div id = "tip2"> </div>
    4. <Ul id = "menu2">
    5. <Li class = "hover" onmouseover = "nowtab (2, 0)"> <a href = "#"> News </a> </li>
    6. <Li onmouseover = "nowtab (2, 1)"> <a href = "#"> comment </a> </li>
    7. <Li onmouseover = "nowtab (2, 2)"> <a href = "#"> Technology </a> </li>
    8. <Li onmouseover = "nowtab (2, 3)"> <a href = "#"> comments </a> </li>
    9. </Ul>
    10. </Div>
    11. <Div class = "main" id = "main2">
    12. News content
    13. </Div>

Who has copied a TAB created by DIV + CSS?

We have just collected:

<Style>
* {Margin: 0; padding: 0 ;}
Ul {list-style: none}
Body {font-size: 12px}
# TabMenus {width: 400px; margin: 100px auto 0 auto; overflow: hidden; border: # ccc solid 1px; border-bottom: none ;}
# TabMenus li {float: left; width: 100px; height: 25px; line-height: 25px; background: # ccc; text-align: center}
# TabMenus li a {display: block; height: 100%; color: #000000; text-decoration: none}
# TabMenus li. current {background: # fff}
# TabMenus li. usual {background: # ccc ;}
# TabCons {clear: both; width: 400px; margin: 0 auto; overflow: hidden; border: # ccc solid 1px; border-top: none}
# TabCons. con {float: left; padding: 10px; width: pixel PX; display: none}
</Style>
<Script>
Function tab (menus, cons, openClass, closeClass, speed ){
Var count = menus. length; // number of options.
Var now = 1; // specifies the option to record the current slide.
Var timer = null ;//

Var clearOpenClass = function () {// clear the slide style.
For (var I = 0; I <count; I ++)
{
Menus [I]. className = closeClass;
Cons [I]. style. display = "none ";
}
};

Var changeTab = function (v) {// Add slide style and content switching.
ClearOpenClass ();
Menus [v]. className = openClass;
Cons [v]. style. display = "block ";
Now = v + 1;
};

Var autoChange = function () {// Automatic Switch
If (now <count ){
ChangeTab (now );
} Else {
Now = 0;
ChangeTab (now );
}
};

Var ...... remaining full text>

Tab Effect of div css

<Span id = "ContentArea"> <Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> webpage effects </title>
</Head>
<Style type = "text/css">
# DNavBar {
Background-color: # ffffff;
}
# DNavBar li {
List-style-type: none;
Float: left;
Width: 84px;
Height: 28px;
Line-height: 28px;
Font-size: 12px;
Color: # FFFFFF;
Border: 3px solid # ffffff;
Background-color: # 86C2FF;
Text-align: center;
Display: block;
Cursor: pointer;
}
# SubMenu {
Background-color: # 0000FF;
Width: 500px;
Border-left: 3px solid # ffffff;
Border-right: 3px solid # ffffff;
Height: 29px;
Line-height: 29px;
Color: # FFFFFF;
Font-size: 12px;
Padding-left: 10px;
}
Body {
Margin-left: 0px;
Margin-top: 0px;
Margin-right: 0px;
Margin-bottom: 0px;
}
A: link {
Color: # FFFFFF;
Text-decoration: none;
}
A: hover {
Color: # FFFFFF;
Text-decoration: none;
}
A: visited {
Color: # FFFFFF;
Text-decoration: none;
}
</Style>
<Script language = "javascript">
Function ShowMenu ()
{
Var barCTT = document. getElementById ("dNavBar ")
Var liArr = barCTT. getElementsByTagName ("li ")
Var links = new Array ()
Links [0] = "<a href = '#'> current location: Home Page"
Links [1] = "<a href = '#'> Project 1 </a> | <a href = '#'> Project 2 </a> | <a href = '#'> Project 3 </a> | <a href = '#'> Project 4 </a>"
Links [2] = "<a href = '#'> Project 1 </a> | <a ...... the remaining full text>

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.