Summary and Comparison of CSS Mainstream Layouts (3) Two-column Layout
This time we continue to summarize the way and principle of the two-column layout in the mainstream layout of CSS.
First, let’s talk about what a two-column layout is.
The two-column layout generally specifies the width and Self-Adaptation layout. The left column of the two columns determines the width, and the right column is a layout effect that automatically fills all the remaining space.
float
Code
1 |
|
Principle
float
The float CSS property specifies that an element should be placed along the left or right side of its container, allowing text and internal connection elements to wrap around it. The element is removed from the normal flow of web pages (doc flow), although still partially liquid (as opposed to绝对定位On the contrary).
** Floating element ** Yes
Since float implies using block layout, it modifies [‘display’] in some cases (https://developer.mozilla.org/zh-CN/docs/Web/CSS/display)
What will be modified specifically can be referred to: https://developer.mozilla.org/zh-CN/docs/Web/CSS/float
Advantages
Implementation is simple
Disadvantage
The self-adaptation margin must be the same as the width of the fixed-width element.
Floating fixed-width elements and not floating Self-Adaptation elements can cause display problems in older browsers.
Display problems can occur when child elements in floating elements use clear to clear the float.
Improve
1 |
|
The improved version can solve the second and third shortcomings
float
Code
1 |
|
Principle
overflow
The CSS property overflow is defined when the content of an element is too large to fit 块级格式化上下文 Time to do. It is overflow-x
Andoverflow-y
Of 简写属性 。
This option includes cutting, displaying scrollbars, or displaying content that spills out of the container into the surrounding area.
Specifying a value other than visible (the default) will create a new 块级格式化上下文This is technically necessary - if a floating element intersects the scrollbar, it will forcibly repackage the content after each scroll step, resulting in a slow scrolling experience.
For’overflow ‘to be effective, the block-level container must have a specified height (’ height ‘or’max-height’) or set’white-space ‘to’nowrap’.
Advantages
None of the problems in the first plan
Disadvantage
The overflow attribute not only enables BFC mode, but also sets the out of memory condition
display:table
Code
1 |
|
Principle
display:table
These elements behave like HTML table
elements. It defines a block-level box.
table-layout
The table-layout CSS property defines the algorithm used to layout the table cells, rows, and columns.
Most browsers use automatic table layout algorithms to layout tables. The width of tables and cells depends on the content they contain.
- fixed
The width of the table and columns is set by the width of the table, and the width of a column is only determined by the cell in the first row of the column. In the current column, the row after the row where the cell is located does not affect the entire column width.
When using “fixed” layout mode, the entire table can be parsed and rendered after the first row is downloaded. This can speed up rendering for “automatic” automatic layout mode, but the contents of subsequent cells will not Self-Adaptation the current column width. Any cell containing overflow content can use overflow
Property controls whether out of memory is allowed.
Advantages
Good compatibility
Disadvantage
Will be subject to table constraints