等高布局 圣杯布局 双飞翼布局

等高布局

假等高

通过设置padding 与margin值相抵消来达到等高 注意:父元素一定要设置溢出隐藏 overflow:hidden;
父元素靠内容撑开 所以他的高等于最高的子元素的高

father{
			
			overflow:hidden;
}
div{
		float:left;
		padding-bottom:9999px;
		margin-bottom:-9999px;
}

真等高

根据内容撑开父盒子的原理,通过嵌套达到等高的效果。有几列就嵌套几个盒子。
HTML结构如下:

<div class="wrap">
        <div class="a">
            <div class="b">
                <div class="c">
                    <div class="col1"></div>
                    <div class="col2"></div>
                    <div class="col3"></div>
                    <div style="clear: both"></div>
                </div>
            </div>
        </div>
    </div>

样式:

<style>
        .wrap{
            width: 1200px;
            overflow: hidden;
        }
        .a {
            width: 100%;
            background-color: blueviolet;
        }

        .b {
            width: 100%;
            background-color: green;
            margin-left: -600px;

        }

        .c {
            width: 100%;
            background-color: red;  
            margin-left: -400px;
        }

        .col1 {
            float: left;
            width: 200px;
            height: 400px;
            background-color: red;
            position: relative;
            left: 1000px;
            
        }

        .col2 {
            float: left;
            width: 400px;
            height: 500px;
            background-color: green;
            position: relative;
            left: 1000px;
        }

        .col3 {
            float: left;
            width: 600px;
            height: 600px;
            background-color: blueviolet;
            position: relative;
            left: 1000px;
        }
    </style>

圣杯布局

<div class="c">
          <!-- 100% -->
          <div class="center">中间盒子</div>
      
        <!-- 固定宽度 -->
        <div class="left">左列</div>
     
      
        <div class="right">右列</div>

        <div style="clear:both"></div>
    </div>
  .c {
        /* width: 100%;不能设置100%  会溢出!!!!!!!!!!!!!!!! */
      
        /* 可以300px 不能小于 保持300px */
        min-height: 300px;
        height: auto;
        padding: 0px 200px;
    }
    .left,.right {
        width: 200px;
        height: 300px;
        
    }
    .left {
        background-color: aqua;
        float: left;
        margin-left: -100%;

        position: relative;
        left:-200px;
    }
    .right {
        background-color: darkred;
        float: left;
        margin-left: -200px;
        position: relative;
        right: -200px;
    }
    .center {
        width: 100%;
        height: 300px;
        background-color: yellowgreen;
        float: left;
    }

双飞翼布局

        <div class="inner"> 中间盒子</div>
          
       
    </div>
  
    <!-- 固定宽度 -->
    <div class="left">左列</div>
 
  
    <div class="right">右列</div>

    <div style="clear:both"></div>
</div>
 .c {
      
        /* 可以300px 不能小于 保持300px */
        min-height: 300px;
        height: auto;
     
    }
    .left,.right {
        width: 200px;
        height: 300px;
        
    }
    .left {
        background-color: aqua;
        float: left;
        margin-left: -100%;
      
    }
    .right {
        background-color: darkred;
        float: left;
        margin-left: -200px;
       
    }
    .center {
        width: 100%;
        height: 300px;
        background-color: yellowgreen;
        float: left;
    }
    .inner {
        margin: 0px 200px;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值