The width:100% and Width:auto differences between CSS

Source: Internet
Author: User

The width:100% and Width:auto differences between CSS

First, the question

The previous time in the adjustment of the tree structure, found that if the tree node name is relatively long, the IE6 will not open the outside elements, resulting in the node name only half, while the icon and name wrapping display, but in IE8 and IE9 display normal. After locating the problem, the final discovery is caused by the following properties, such as red, and setting the value of width to auto solves the problem:

. Treeview. TreeView ul{

padding:0px 0px 0px 19px;

List-style:none;

margin:0px 0px;

Width:100%;/* This is changed to auto*/

Background:url (./trstree-default-line.gif) repeat-y 0px Center;

}

Ii. Conclusion

[1] width:100% does not contain the attribute value of the Margin-left margin-right, directly to the width of its parent container plus a value containing margin-left/margin-right. If margin is set, then the new width value is the width of the container plus the value of margin. (careful observation) will find added margin corresponding to the side will be more than the set of blank. and the horizontal scroll bar will be extra because the width is beyond the range of the screen. (This is body relative to the parent container).

[2] Width:auto contains the property value of Margin-left/margin-right. Its value contains the value of Margin-left/margin-right. Width:auto always occupy the whole line !!! The value of margin is already included (that is, a whole line) if you want to set the value of margin then use a whole line and subtract the value of margin to get the current width. This value is subtracted from the corresponding edge blank. The notable feature is that this does not appear as a horizontal scroll bar, which means that the width does not increase.

[3] Under the IE6 is not normal, but in IE8 and IE9 display Normal, may be IE8 and IE9 to width:100% resolution and IE6 different, but the two to Width:auto resolution is consistent.

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.