Home>Article>Web Front-end> How to implement two column layout in css
Method: 1. Set "dislpay:inline-block" on both box elements; 2. Set both box elements to float; 3. The left fixed-width element is floated, and the right element is set to margin-left. And the value is greater than the width of the fixed-width element; 4. Floating BFC; 5. Absolute positioning margin-left, etc.
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
There are two types of two-column layouts. One is fixed width on the left and adaptive on the right. One is that both columns are adaptive (that is, the left width is determined by the child elements, and the right side fills in the remaining space). CSS interview questions are common test questions and are also skills that a front-end development engineer must master. The implementation methods will be introduced below.
Principle: Set dislpay:inline-block on both elements. To eliminate the influence of HTML spaces, the font-size of the parent element needs to be set to 0, and the width of the adaptive element on the right is calculated using the calc function. If the heights of the two elements are different, you can set vertical-align:top adjustment for the elements.
Disadvantages: Since the font-size of the parent element is set to 0, the text in the child element will not be displayed
12341234
Principle: Two elements are set to float, and the width of the adaptive element on the right is calculated using the calc function
Disadvantages: Parent Elements need to be cleared from floating
123adadadddddddddddddddddddddddddddddddddddddddd
## Principle: Fixed-width elements on the left are floating, and elements on the right are floating The adaptive element can set the margin-left value to be greater than the width of the fixed-width element
Disadvantages: The parent element needs to clear the float
1234
1234
Principle: The parent element sets overflow:hidden, the left fixed-width element floats, and the right adaptive element sets overflow:auto to create BFC
Disadvantages: If the content of the left element exceeds the set width, it will overlap the right element
111111111111111111111111111111111111111111111111111111111111111111111
Principle: The parent element is positioned relatively, the left element is positioned absolutely, and the right adaptive element sets the margin-left value to be greater than the width of the fixed-width element
Disadvantages: The parent element is set to relative positioning
Principle: The parent element sets display: flex, and the adaptive element sets flex: 1
Disadvantages: There are compatibility issues, and it is not supported below IE10
126545453dddddddd45345345312121
The principle and shortcomings are the same as the flex layout above
Disadvantages: too compatibility Poor, IE11 does not support it, only Google 57 and above can
(Learning video sharing: css video tutorial 1111111111111111111111111
The above is the detailed content of How to implement two column layout in css. For more information, please follow other related articles on the PHP Chinese website!