


How to create block-level formatting context? The role of block-level formatting context
What is block-level formatting context in css? Block Formatting Context is part of the visual rendering of CSS on web pages and is used to determine the layout of block boxes. In the Positioning Scheme, it belongs to the Normal Flow. So how to create a block-level formatting context? What are the requirements to create block-level formatting? This article will explain it to you one by one.
FC (Formatting Context) translates to formatting context/formatting range, which refers to an area in the page layout. It has its own rendering rules and determines how its own sub-elements are laid out. and its relationship and role with other elements.
According to CSS display classification, xhtml elements are divided into three types: block elements, inline elements, and variable elements. When adding styles to page elements, we need to know what type the element is, and then we can convert the element type ourselves. Just like we can use display to turn an inline element into a block element (display: block). There are several special elements img, and input is inline-block by default;
What is a block formatting context (BFC)? Equivalent to a special area.
If an element meets the conditions for becoming a BFC, the element becomes an isolated independent container. The internal elements of the element will be arranged vertically along the border of its parent element, and will not affect each other's external elements. .
The conditions for triggering BFC are as follows:
1. Floating elements, float values other than none
2. Absolutely positioned elements, position (absolute , fixed)
3. display is one of the following values: inline-blocks, table-cells, table-captions. //It is a block container that is not a block-level box
4. Overflow values other than visible (hidden, auto, scroll)
If one of the above four conditions is met, it can be created Block-level formatting context, the environment in which the content is located is the environment of the block-level formatting context.
In CSS3, BFC is called Flow Root, and some trigger conditions are added:
1, display table-caption value
2, The fixed value of position is actually a subclass of absolute, so using this value in CSS2.1 will also trigger BFC, but this is made clearer in CSS3.
The element sets the IE-specific CSS attribute zoom: 1 to trigger hasLayout. zoom is used to set or retrieve the zoom ratio of the element. A value of "1" means using the actual size of the element. Using zoom: 1 both It can trigger hasLayout without causing other effects on the elements, which is relatively more convenient. This is the situation under IE
The role of block-level formatting context (BFC):
(1) BFC will prevent margins from folding
I understand that folding means that the outer margins will overlap and will not be clearly distinguished, just like what's yours is mine, and what's mine is yours.
Rules for margin collapse: Only when two block-level elements are adjacent and in the same block-level formatting context, the vertical margins between them will overlap. That is, even if two block-level elements are adjacent, their margins will not collapse when they are not in the same block-level formatting context. Therefore, preventing margins from collapsing simply results in a new BFC.
But for two adjacent elements, it doesn’t mean much. There is no need to add a shell to them, but it is necessary for nested elements. Just set the parent element to BFC. . In this way, the margin of the child element will not collapse with the margin of the parent element.
(2) BFC can contain floating elements
This means that sub-elements in BFC will not exceed its containing block, while elements with absolute position can exceed it. The containing block border
(3) BFC can prevent elements from being covered by floating elements
This is based on the left side of the margin box of each element, and the containing block border box touch the left side of (for left-to-right formatting, otherwise vice versa). This is true even if there is float. This principle is realized.
Recommended related articles:
CSS > Translation: Understanding block-level formatting context in CSS_html/css_WEB-ITnose
CSS understands block-level formatting context BFC
The above is the detailed content of How to create block-level formatting context? The role of block-level formatting context. For more information, please follow other related articles on the PHP Chinese website!

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

How much time do you spend designing the content presentation for your websites? When you write a new blog post or create a new page, are you thinking about

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

No matter what stage you’re at as a developer, the tasks we complete—whether big or small—make a huge impact in our personal and professional growth.

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

I was just chatting with Eric Meyer the other day and I remembered an Eric Meyer story from my formative years. I wrote a blog post about CSS specificity, and

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.
