等高布局

等高布局:
让left,center,right三个盒子根据最高的盒子进行等高布局,由于不知道哪个盒子最高,故给每一个盒子都设置等高布局的核心样式(padding-bottom: 10000px; margin-bottom: -10000px;)。

等高布局的原理:
当给较低子元素一个padding-bottom的值,随着这个值得变大,整个父级的高度会随之变大,这个时候给他一个margin-bottom的负值,就会减少该子元素占用父级元素的margin空间,当减少到刚小于最高高度的盒子的后,即使margin-bottom的负值继续变化,整个父级的高度也不会再变化,因为这个时候整个父级的高度已经被最高高度的盒子撑开,即到达了等高的效果。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>等高布局</title>
    <link rel="stylesheet" href="./reset.css">
    <style>
        .outer{
            padding:  0 100px;
            overflow: hidden;
        }
        .center{
            /*padding: 0px 100px;*/
            /*height: 100px;*/
            width: 100%;
            float: left;
            background-color: red;

            /*等高布局:*/
            padding-bottom: 10000px;
            margin-bottom: -10000px;
        }
        .left{
            float: left;
            width: 100px;
            background-color: yellowgreen;
            margin-left: -100%;
            position: relative;
            left: -100px;

            /*等高布局:*/
            padding-bottom: 10000px;
            margin-bottom: -10000px;
        }
        .right{
            float: left;
            width: 100px;
            /*height: 100px;*/
            background-color: #4c71ff;
            margin-left: -100px;
            position: relative;
            right: -100px;

            /*等高布局:*/
            padding-bottom: 10000px;
            margin-bottom: -10000px;
        }
    </style>
</head>
<body>
<div class="outer">
    <div class="center">
        center <br>
        center
    </div>
    <div class="left">
        left <br>
        left <br>
        left <br>
        left <br>
        left <br>
        left <br>
        left <br>
    </div>
    <div class="right">
        right
    </div>
</div>
</body>
</html>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容