Table of Contents
Learning about hasLayout and Block formatting contexts
What is hasLayout?
What are Block formatting contexts?
Home Web Front-end HTML Tutorial Learning about hasLayout and Block formatting contexts (Part 1)_html/css_WEB-ITnose

Learning about hasLayout and Block formatting contexts (Part 1)_html/css_WEB-ITnose

Jun 24, 2016 am 11:39 AM

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及以下版本。
Copy after login

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>	<hr>	<input>, <button>, <select>, <textarea>, <fieldset>, <legend>	<iframe>, <embed>, <object>, <applet>	<marquee>对于并非所有的元素都默认有布局,微软给出的主要原因是“性能和简洁”。如果所有的元素都默认有布局,会对性能和内存使用上产生有害的影响。http://www.satzansatz.de/cssd/onhavinglayoutrev07-20060517.html
Copy after login

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.

  • display: inline-block
  • height: (any value except auto)
  • width: (any value except auto)
  • float: (left or right)
  • position: absolute
  • writing-mode: tb-rl
  • zoom: (any value except normal)
  • Internet Explorer 7 also 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 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 :

  • The internal Boxes will be placed one after another in the vertical direction.
  • The vertical distance of the Box is determined by margin. The margins of two adjacent boxes belonging to the same BFC will overlap
  • The left side of the margin box of each element is in contact with the left side of the containing block border box (for a left-to-right format ation, otherwise the opposite). This is true even if there is float.
  • The BFC area will not overlap with the float box.
  • BFC is an isolated independent container on the page. The sub-elements inside the container will not affect the elements outside. And vice versa.
  • When calculating the height of BFC, floating elements also participate in the calculation.
  • In CSS3, this concept has been changed: http://www.w3.org/TR/css3-box/#block-level0
    In CSS3, BFC is called flow root.
  • How to trigger BFC?

  • float: (any value except none)
  • overflow: (any value except visible)
  • display:(table-cell/table-caption/inline-block)
  • position: (any value except static/relative)
    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.

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    Repo: How To Revive Teammates
    4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    Hello Kitty Island Adventure: How To Get Giant Seeds
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update? Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update? Mar 04, 2025 pm 12:32 PM

    The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

    How do I use HTML5 form validation attributes to validate user input? How do I use HTML5 form validation attributes to validate user input? Mar 17, 2025 pm 12:27 PM

    The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

    How to efficiently add stroke effects to PNG images on web pages? How to efficiently add stroke effects to PNG images on web pages? Mar 04, 2025 pm 02:39 PM

    This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

    What are the best practices for cross-browser compatibility in HTML5? What are the best practices for cross-browser compatibility in HTML5? Mar 17, 2025 pm 12:20 PM

    Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

    What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

    The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

    What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

    The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

    How do I use the HTML5 <time> element to represent dates and times semantically? How do I use the HTML5 <time> element to represent dates and times semantically? Mar 12, 2025 pm 04:05 PM

    This article explains the HTML5 &lt;time&gt; element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

    What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

    The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

    See all articles