To better understand css, especially the rendering of css under IE, haslayout is a concept that needs to be thoroughly understood. Most display errors under IE are caused by haslayout.
What is haslayout?
Haslayout is an internal component of the Windows Internet Explorer rendering engine. In Internet Explorer, an element either calculates the size and organizes its own content, or relies on a parent element to calculate the size and organize the content. In order to reconcile these two different concepts, the rendering engine uses the hasLayout attribute, which can be true or false. When the hasLayout attribute value of an element is true, we say that the element has a layout
When an element has a layout, it is responsible for size calculation and positioning of itself and possible descendant elements. Simply put, this means that the element needs to spend more time maintaining itself and its contents, rather than relying on ancestor elements to do this work. Therefore, some elements will have a layout by default. When we say that an element "has layout" or "gets layout", or that an element "has layout", we mean that its Microsoft-specific property hasLayout is set to true. A "layout element" can be an element that has a layout by default or an element that has a layout by setting certain CSS properties. If an HTML element has haslayout attribute, then the value of haslayout of this element must be only true. haslayout is a read-only attribute. Once triggered, it is irreversible. You can check whether HTML elements under IE have haslayout through IE Developer Toolbar. Under IE Developer Toolbar, elements with haslayout are usually displayed as "haslayout = -1".
Elements responsible for organizing their own content will have a layout by default, mainly including the following elements (incomplete list):
* body and html
* table, tr, th, td
* img
* hr
* input, button, file, select, textarea, fieldset
* marquee
* frameset, frame, iframe
* objects, applets, embed
For not all elements There is a layout by default, and the main reason given by Microsoft is "performance and simplicity." If all elements were laid out by default, it would have a detrimental impact on performance and memory usage.
How to activate haslayout?
Most IE display errors can be corrected by activating the haslayout attribute of the element. You can activate the element's haslayout by setting the css size attribute (width/height), etc., so that it "has layout". Just set the following css properties as shown below.
* display: inline-block
* height: (any value except auto)
* float: (left or right)
* position: absolute
* width: (any value except auto )
* writing-mode: tb-rl
* zoom: (any value except normal)
Internet Explorer 7 has some additional properties (not a complete list):
* min-height: (any value)
* max-height: (any value except none)
* min-width: (any value)
* max-width: (any value except none)
* overflow: (any value except visible)
* overflow-x: (any value except visible)
* overflow-y: (any value except visible)
* position: fixed
where overflow-x and overflow-y are attributes in the CSS3 box model, which are not yet widely supported by browsers.
For inline elements (the default is inline elements, such as span, or elements with display:inline;),
width and height are only available under IE5.x and IE6 or newer HasLayout is triggered in quirks mode of the version. For IE6, if the browser is running in standards compatibility mode, inline elements will ignore the width or height attributes, so setting width or height cannot order the element to have layout in this case.
Zoom can always trigger hasLayout, but it is not supported in IE5.0.
If an element with "layout" displays: inline at the same time, its behavior is very similar to the inline-block mentioned in the standard: it is arranged horizontally and continuously in the paragraph like ordinary text, subject to vertical-alignInfluence, and the size can be adjusted adaptively according to the content. This can also explain why in IE/Win alone, inline elements can contain block-level elements with less problems, because in other browsers, display: inline means inline, unlike IE/Win, once the inline element has a layout, it still has a layout. Will become inline-block.
Debugging and solving haslayout problems
When a web page behaves abnormally in IE, you can try to activate haslayout to see if the problem lies. A common method is to set zoom:1 to the css of an element. Zoom:1 is used because in most cases it fires the element's haslayout without affecting the existing environment. Once the problem disappears, it can basically be determined that it is the cause of haslayout. Then you can correct this problem by setting the corresponding css properties. It is recommended that the first thing to consider is to set the width/height attributes of the element, and then consider other attributes.
For IE6 and earlier versions, the common method is called Holly hack, which is to set the height of this element to 1% (height:1%;). It should be noted that this method will not work when the overflow property of this element is set to visible. Or use IE's conditional comments.
For IE7, the best method is to set the minimum height of the element to 0 (min-height:0;).
Common bugs caused by haslayout issues
Double margin floating bug in IE6 and lower versions
Bug fix: display:inline;
3 pixel offset bug in IE5-6/win
Bug fix: _height:1%;
E6 peek-a-boo bug
Bug fix: _height:1%;
The above is the detailed content of Thorough understanding of CSS haslayout. For more information, please follow other related articles on the PHP Chinese website!