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)
time(); function Function prototype: time_t time(...
Table of contents VMware BurpSuite 1. Virtual mac...
I will explain the installation of MySQL under Wi...
This article records the installation and configu...
Closure implementation of private variables Priva...
I recently started learning database, and I feel ...
Table of contents Basic syntax for multi-table jo...
In order to centrally manage the images we create...
Table of contents 1. Custom routing 2. Tab naviga...
After minimizing the installation of Python8, I i...
The difference between relative and absolute in H...
What is an inode? To understand inode, we must st...
Add in the <Head> tag <meta http-equiv=&q...
When making a web page, we usually need to consid...
1. Download docker online yum install -y epel-rel...