Home Web Front-end CSS Tutorial What are the formatting context (FC) types in CSS layout? Introduction to formatting context (FC) types

What are the formatting context (FC) types in CSS layout? Introduction to formatting context (FC) types

Aug 03, 2018 pm 04:48 PM
bfc css html html5 layout

What is formatting context (FC)? Formatting Context (Formatting Context) refers to a rendering area in the page, which has a set of rendering rules, which determines how its sub-elements are positioned, as well as their interaction and interaction with other elements. So what are the formatting contexts in CSS layout? ? The following article introduces you to several types of formatting context.

Block Level Format Context (BFC):

What is BFC? Block Formatting Context, block-level formatting context, is an independent block-level rendering area. This area has a set of rendering rules to constrain the layout of block-level boxes and has nothing to do with the outside of the area.

BFC’s constraint rules

1. The internal BOX will be placed one after another in the vertical direction;

2. The distance in the vertical direction is determined by margin. (The complete statement is: the margins of two adjacent BOXs belonging to the same BFC will overlap, regardless of the direction.)

3. The left margin of each element is consistent with the left boundary of the containing block. touching (left to right), even for floated elements. (This shows that the child elements in BFC will not exceed its containing block, and the element with absolute position can exceed the boundary of its containing block);

4. The BFC area will not overlap with the float element area. ;

5. When calculating the height of BFC, floating child elements also participate in the calculation;

6. BFC is an isolated independent container on the page, and the child elements in the container will not be affected. External elements, and vice versa;

Application of BFC

  • Prevent margin from overlapping

  • Prevent height collapse caused by floating

How to generate BFC

  • ## The value of #float is not none; the value of

  • overflow is not visible;## The value of

  • #display

    is inline-block table-cell table-caption;## The value of

  • #position
  • is

    absolute or fixed; ##display: Table also thinks that BFC can be generated? In fact, Table will generate an anonymous table-cell by default, and it is this anonymous table-cell that generates BFC.

Inline Formatting Context (IFC):

What is IFC? IFC (Inline Formatting Contexts) literally translates as "inline formatting context". The height of IFC's line box (wire frame) is calculated from the highest actual height of the inline elements it contains (not affected by vertical padding/margin)

Features of IFC

1. The line box in IFC is generally close to the entire IFC on the left and right sides, but it will be disturbed by float elements. The float element will be located between the IFC and the line box, shortening the width of the line box.

2. It is impossible to have block-level elements in IIFC. When inserting block-level elements (such as inserting a div in p), two anonymous blocks will be generated separated from the div, that is, two IFCs will be generated. Each IFC appears as a block-level element, arranged vertically with the div.

Application of IFC

Horizontal centering: When a block is to be horizontally centered in the environment, set it to

inline-block
    will generate
  1. IFC

    in the outer layer, and text-align can be used to center it horizontally. Vertical centering: Create an

    IFC
  2. , use one of the elements to expand the height of the parent element, and then set its
  3. vertical-align:middle

    , other inline elements can be vertically centered under this parent element.

  4. Grid Layout Formatting Contexts (GFC)

GFC(GridLayout Formatting Contexts)Literally translated as "grid layout formatting context", when the

display

value is set to grid for an element, this element will get an independent rendering area. We can pass Define grid definition rows (grid definition rows) and grid definition columns (grid definition columns) properties on the grid container (grid container) . Define grid row (grid row) and grid column (grid columns) on grid item (grid item) for each grid item (grid item)Define position and space. GFC will change the traditional layout mode, it will change the layout from one-dimensional layout to two-dimensional layout. Simply put, with

GFC

, the layout is no longer limited to a single dimension. At this time, it is extremely easy for you to achieve layout effects such as nine-square grid and puzzle. Adaptive Formatting Context (FFC):

FFC (Flex Formatting Contexts) literally translates as "adaptive formatting context", display Elements with a value of flex or inline-flex will generate a flex container.

Flex Box consists of flex containers and flex projects. You can get a flex container by setting the element's display property to flex or inline-flex. A container set to flex is rendered as a block-level element, while a container set to inline-flex is rendered as an inline element.

Each child element in the flex container is a flex item. There can be any number of flex items. All elements outside the flex container and within the flex project are unaffected. Simply put, Flexbox defines how flex items should be laid out within a flex container.

The difference between adaptive formatting context (FFC) and block-level formatting context (BFC):

FFC is somewhat similar to BFC, but there are still the following differences:

1. Flexbox does not support the two pseudo-elements::first-line and ::first-letter

2. Vertical-align has no effect on child elements in Flexbox

3. The float and clear attributes have no effect on child elements in Flexbox, nor will they cause the child elements to break away from the document flow (but they have an effect on Flexbox!)

4. Multi-column layout (column- *) It is also invalid in Flexbox, which means that we cannot use multi-column layout in Flexbox to arrange the child elements under it

5. The child elements under Flexbox will not inherit the width of the parent container

Recommended related articles:

CSS > Translation: Understanding block-level formatting context in CSS_html/css_WEB-ITnose

CSS > Various height calculations in inline formatting context_html/css_WEB-ITnose

Detailed explanation of how block formatting context, floating and absolute positioning work_html/ css_WEB-ITnose

The above is the detailed content of What are the formatting context (FC) types in CSS layout? Introduction to formatting context (FC) types. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap

Video Face Swap

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

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)

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

React's Role in HTML: Enhancing User Experience React's Role in HTML: Enhancing User Experience Apr 09, 2025 am 12:11 AM

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

What Does H5 Refer To? Exploring the Context What Does H5 Refer To? Exploring the Context Apr 12, 2025 am 12:03 AM

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

See all articles