


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!

I recently found a solution to dynamically update the color of any product image. So with just one of a product, we can colorize it in different ways to show

In this week's roundup, Lighthouse sheds light on third-party scripts, insecure resources will get blocked on secure sites, and many country connection speeds

There are loads of analytics platforms to help you track visitor and usage data on your sites. Perhaps most notably Google Analytics, which is widely used

The document head might not be the most glamorous part of a website, but what goes into it is arguably just as important to the success of your website as its

What's happening when you see some JavaScript that calls super()?.In a child class, you use super() to call its parent’s constructor and super. to access its

JavaScript has a variety of built-in popup APIs that display special UI for user interaction. Famously:

I was chatting with some front-end folks the other day about why so many companies struggle at making accessible websites. Why are accessible websites so hard

There is an HTML attribute that does exactly what you think it should do:


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

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools