三列(多列)等高布局

网页局部布局中,常常出现多列登高布局,因为内容高度不定,所以不能对每一列设置相等的高度。

一、常用方法,亦是《高级web标准解决方案》一书中采用的办法:采用对没列元素添加较大的正底内边距(padding-bottom)等大负值的底外边距(margin-bottom) 

代码结构如下

<div id="container" >
        <div class="box" >
            <p>We created lists of words that begin with ffxdz. All letters were compared to our large Scrabble and Words With Friends database. Every word contained in this list can be played in Scrabble.We created lists of words that begin with ffxdz. All letters were compared to our large Scrabble and Words With Friends database. Every word contained in this list can be played in Scrabble.We created lists of words that begin with ffxdz. All letters were compared to our large Scrabble and Words With Friends database. Every word contained in this list can be played in Scrabble.We created lists of words that begin with ffxdz. All letters were compared to our large Scrabble and Words With Friends database. Every word contained in this list can be played in Scrabble.</p>
        </div>
        <div class="box" >
            <p>We created lists of words that begin with ffxdz. All letters were compared to our large Scrabble and Words With Friends database. Every word contained in this list can be played in Scrabble.We created lists of words that begin with ffxdz. All letters were compared to our large Scrabble and Words With Friends database. Every word contained in this list can be played in Scrabble.</p>
        </div>
        <div class="box" >
            <p>We created lists of words that begin with ffxdz. All letters were compared to our large Scrabble and Words With Friends database. Every word contained in this list can be played in Scrabble.</p>
        </div>
    </div>

css code

body, div,p{ margin: 0; padding: 0;}
#container{ text-align:center;} #container { width: 960px;   margin: 20px auto 0; overflow: hidden; } #container *{ text-align: left;} .box { background: #ccc; float: left; display: inline; width: 258px; padding-top: 20px; padding-right: 20px; padding-left: 20px; margin-right: 30px; margin-bottom: -99999px; padding-bottom: 99999px; border: 1px solid red; } .box:last-child{ margin-right: 0; }

  

  此方法没有兼容性问题,列数可自由定制,可以在包括ie6在内的浏览器都可正常展现,但有一个问题,底边框缺失,如图

解决办法,在每一个box的结构中添加一个空的div,用来展现底边

代码结构

<div id="container" >
        <div class="box" >
            <p>We created lists of words that begin with ffxdz. All letters were compared to our large Scrabble and Words With Friends database. Every word contained in this list can be played in Scrabble.We created lists of words that begin with ffxdz. All letters were compared to our large Scrabble and Words With Friends database. Every word contained in this list can be played in Scrabble.We created lists of words that begin with ffxdz. All letters were compared to our large Scrabble and Words With Friends database. Every word contained in this list can be played in Scrabble.We created lists of words that begin with ffxdz. All letters were compared to our large Scrabble and Words With Friends database. Every word contained in this list can be played in Scrabble.</p>
            <div class="bottom"></div>
        </div>
        <div class="box" >
            <p>We created lists of words that begin with ffxdz. All letters were compared to our large Scrabble and Words With Friends database. Every word contained in this list can be played in Scrabble.We created lists of words that begin with ffxdz. All letters were compared to our large Scrabble and Words With Friends database. Every word contained in this list can be played in Scrabble.</p>
            <div class="bottom"></div>
        </div>
        <div class="box" >
            <p>We created lists of words that begin with ffxdz. All letters were compared to our large Scrabble and Words With Friends database. Every word contained in this list can be played in Scrabble.</p>
            <div class="bottom"></div>
        </div>
    </div>

  css code

body, div,p{ margin: 0; padding: 0;}
#container{text-align:center;} #container { width: 960px;
margin:20px auto 0; overflow: hidden; } #container *{ text-align: left; } #container{ position: relative; /**添加地边框需已容器元素绝对定位**/ zoom: 1; /** ie6 下部分情况margin无效,解决办法是给用到margin的元素的父元素添加 zoom=1 的样式**/ } .box { background: #ccc; float: left; display: inline; width: 258px; padding-top: 20px; padding-right: 20px; padding-left: 20px; margin-right: 30px; margin-bottom: -99999px; padding-bottom: 99999px; border: 1px solid red; } .box:last-child{ margin-right: 0; } .bottom{ height: 1px; position: absolute; bottom: 0; width: 300px; background: red; } .first{ left: 0; } .second{ left: 330px; } .last{ left: 660px; }

  如此便得到带有正常边框的登高三列布局

 

转载于:https://www.cnblogs.com/qingranEvent/p/6588773.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值