


Learning about hasLayout and Block formatting contexts (Part 1)_html/css_WEB-ITnose
Learning about hasLayout and Block formatting contexts
@(css BFC)[IE hasLayout|Miaotong]
What is hasLayout?
haslayout 是Windows Internet Explorer渲染引擎的一个内部组成部分。在InternetExplorer中,一个元素要么自己对自身的内容进行计算大小和组织,要么依赖于父元素来计算尺寸和组织内容。为了调节这两个不同的概念,渲染引擎采用了 hasLayout 的属性,属性值可以为true或false。当一个元素的 hasLayout属性值为true时,我们说这个元素有一个布局(layout)。注意:hasLayout属性是微软特有的过时属性,在IE8、IE9中,hasLayout属性已经被废弃。下文中的InternetExplorer都是指IE7、IE6及以下版本。
When an element has a layout, it is responsible for sizing and positioning 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. 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". ‘Layout’ In IE, you can use the hasLayout attribute to determine whether an element has layout, such as object.currentStyle.hasLayout.
Elements responsible for organizing their own content will have a layout by default, which mainly includes the following elements (incomplete list):
<html>, <body> <table>, <tr>, <th>, <td> <img alt="Learning about hasLayout and Block formatting contexts (Part 1)_html/css_WEB-ITnose" > <hr> <input>, <button>, <select>, <textarea>, <fieldset>, <legend> <iframe>, <embed>, <object>, <applet> <marquee>对于并非所有的元素都默认有布局,微软给出的主要原因是“性能和简洁”。如果所有的元素都默认有布局,会对性能和内存使用上产生有害的影响。http://www.satzansatz.de/cssd/onhavinglayoutrev07-20060517.html
Debugging and solving haslayout issues
When the web page behaves abnormally in IE, you can try to activate haslayout to see if the problem is the problem. 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 the 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 way 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%;
IE6’s peek-a-boo bug
bug fix: height:1%;
IE6/7 negative margin hidden bug:
bug Repair: Remove the hasLayout of the parent element; or assign hasLayout to the child element and add position: relative;
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.
Internet Explorer 7 also has some additional properties (not a complete list):
where overflow-x and overflow-y are Properties in the css3 box model 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 triggered in IE5.x and IE6 or newer versions of quirks mode hasLayout. 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- align affects, 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.
What are Block formatting contexts?
This article refers to the W3C CSS 2.1 specification Visual formatting model
http://www.w3.org/TR/CSS2/
http://www.w3.org/TR/CSS2/visuren .html#inline-level
http://www.w3.org/TR/CSS2/visuren.html#normal-flow
Box: The basic unit of CSS layout
Box is the object and basic unit of CSS layout. From a visual point of view, a page is composed of many Boxes. The type of element and display attribute determine the type of this Box. Different types of Box will participate in different Formatting Context (a container that determines how to render the document), so the elements within the Box will be rendered in different ways. Let’s see what boxes there are:
block-level box: elements with display attributes of block, list-item, table will generate block-level boxes. And participate in block fomatting context;
inline-level box: Elements with display attributes of inline, inline-block, and inline-table will generate inline-level boxes. And participate in inline formatting context;
run-in box: only available in css3, I won’t talk about it for now. http://www.w3.org/TR/css3-box/#run-in-boxes
Formatting context
Formatting context is the W3C CSS2.1 specification a concept in . It is a rendering area on the page and has a set of rendering rules that determine how its sub-elements will be positioned and their relationship and interaction with other elements. The most common Formatting contexts are Block fomatting contexts (BFC for short) and Inline formatting contexts (IFC for short).
There are only BFC and IFC in CSS2.1, and GFC and FFC are also added in CSS3.
BFC definition
BFC (Block formatting contexts) is literally translated as "block-level formatting context". It is an independent rendering area in which only the Block-level box participates. It stipulates how the internal Block-level Box is laid out and has nothing to do with the outside of this area.
BFC layout rules :
In CSS3, BFC is called flow root.
How to trigger BFC?
Note: We sometimes use overflow The :hidden method is used to clear floats because the BFC of the element is triggered (IE6 7 requires zoom to be 1 and triggers hasLayout). You can refer to the detailed explanation of css float
This is the summary for today, and we will continue with the next article tomorrow. If there are any errors or deficiencies, please point them out, thank you very much! ----Miaotong.

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
