HTML & CSS & JS compatible tree (IE, Firefox, chrome) _ HTML/Xhtml _ webpage Creation

Source: Internet
Author: User
What is a tree in WEB design? Simply put, click a link to expand the sub-directory and click "join". This is the simplest tree. How to implement it is also very simple. css has an attribute "display, this can control whether the content is actually not displayed, so you can use js to control css attributes. See the following code: & lt; div & gt; top-level directory & lt; div & gt; what is a tree in WEB design? Simply put, click a link to expand the sub-directory and click "join". This is the simplest tree. How to implement it is also very simple. css has an attribute "display, this can control whether the content is actually not displayed, so you can use js to control css attributes. See the following code:

Top-level directory



Menu 1


Menu 2


Menu 3



This is even the prototype of the tree. Of course, the display attribute of css is added to the initial state. The most common attribute of display is none and block.
None indicates that the block is not displayed, while the block is displayed as a block type element.

Top-level directory



Menu 1


Menu 2


Menu 3



In this way, only the top-level directory is displayed when you run the page. If you want to control the page, you need to add the js Code.
1. Obtain menulist first
Var menulist = document. getElementById ("menulist ");
2. You can control the CSS attributes of the object.
Menulist. style. display = "block ";
Add judgment
If (menulist. style. display = "none ")
Menulist. style. display = "block ";
Else
Menulist. style. display = "none ";
In this way, the original tree is generated, and the final code
Script
Function showmenu ()
{
Var menulist = document. getElementById ("menulist ");
If (menulist. style. display = "none ")
Menulist. style. display = "block ";
Else
Menulist. style. display = "none ";
}
Script

Click = "showmenu ();"> top-level directory



Menu 1


Menu 2


Menu 3



For a long time, I used this method to create an attribute directory. No matter how complicated the directory to be created is, this method has been tried and tested, the following figure shows the running effect of the complex tree directory on IE:


The terrible thing happened in chrome. After some information retrieval, I finally found the reason. In addition to block and none, the display still has many other attributes. The block is displayed in blocks, I used tables to deploy them above. God knows whether tables and blocks have deep hatred. Microsoft thinks it is wise to ignore their hatred. chrome is still very old to abide by standards, and firefox is the same, so there is still a problem in their explanation. How can we solve this problem:
Display also has an Attribute table-cell, that is, to render the content in the form of a table. This is exactly the case when I use the table layout. The following shows the compatibility of the three browsers:

IE6

Chrome2

Firefox3.5

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.