Initially, multiple columns have different content sizes and heights. Now you need to set different backgrounds to display, and the height of each column needs to be consistent. Then this requires the use of multi-column equal height layout. The final desired effect: 1. True equal height layout flex technical point: flexible box layout flex, the default value is the feature of built-in equal height layout. When defining a flex layout, there are some default values. <div class="box"> <div class="left"></div> <div class="center"></div> <div class="right"></div> </div> CSS .box { display: flex; } .left { width: 300px; background-color: grey; } .center { flex: 1; background: red; } .right { width: 500px; background: yellow; } See the Pen equal-hight-layout-flex by weiqinl ( @weiqinl ) on CodePen . 2. True equal height layout table-cell Technical point: The table layout naturally has the characteristic of equal height. If display is set to HTML Structure <div class="box"> <div class="left"></div> <div class="center"></div> <div class="right"></div> </div> CSS Styles .left { display: table-cell; width:30%; background-color: greenyellow; } .center { display: table-cell; width:30%; background-color: gray; } .right { display: table-cell; width:30%; background-color: yellowgreen; } 3. Positive and negative values of bottom inner and outer margins in fake equal-height column layout Implementation: Set the overflow property of the parent container to hidden. Give each column a large bottom padding, then use negative margins of similar value to offset this height.
Technical Points
HTML Structure <div class="box"> <div class="left"></div> <div class="center"></div> <div class="right"></div> </div> CSS .box { overflow: hidden; } .box > div{ /** * Set padding-bottom to a larger positive value. * Set margin-bottom to a negative value with a large absolute value. **/ padding-bottom: 10000px; margin-bottom: -10000px; float:left; width:30%; } .left { background-color: greenyellow; } .center { background-color: gray; } .right { background-color: yellowgreen; } 4. Fake equal height layout, background visual effect Technical point: float float, and set the width of each column. Set the parent element to an inline block-level element, and then use a linear gradient image to set the background of the parent element to highlight the same height effect The CSS <div class="box five-columns"> <div class="col"></div> <div class="col"></div> <div class="col"></div> <div class="col"></div> <div class="col"></div> </div> CSS /** You need to calculate the average width of each column yourself*/ .box { display: inline-block; background: linear-gradient( to right, red, red 20%, blue 20%, blue 40%, yellow 40%, yellow 60%, orange 60%, orange 80%, grey 80%, grey); } .col { float: left; width: 16%; padding: 2%; } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. |
<<: Simple example of adding and removing HTML nodes
>>: How to configure anti-hotlinking for nginx website service (recommended)
Preface This is an investigation caused by the ex...
Linux often encounters situations such as adding ...
Method 1: Download Pycharm and install Download a...
The div element is used to provide structure and b...
This article shares the specific code of the WeCh...
Table of contents 1. Use default parameters inste...
The specific usage of the Vue image drag and drop...
Storage rules for varchar In versions below 4.0, ...
Let's take a look at my error code first. htm...
This article records the detailed tutorial for in...
When I was printing for a client recently, he aske...
Application Scenario Taking the background manage...
Table of contents Chain calls A small case Chain ...
This article shares the specific code for importi...
1. Documentation Rules 1. Case sensitive. 2. The a...