等高布局如何?

來源:互聯網
上載者:User
padding補償法
首先把列的padding-bottom設為一個足夠大的值,再把列的margin-bottom設一個與前面的padding-bottom的正值相抵消的負值,父容器設定超出隱藏,這樣子父容器的高度就還是它裡面的列沒有設定padding-bottom時的高度,當它裡面的任一列高度增加了,則父容器的高度被撐到它裡面最高那列的高度,其他比這列矮的列則會用它們的padding-bottom來補償這部分高度差。

<!DOCTYPE html><html><head>    <style>        *{margin: 0;padding: 0;}        .container{width: 600px;border: 1px solid black;overflow: hidden}                .left{float: left;width: 150px;border: 2px solid red;                padding-bottom: 2000px;margin-bottom: -2000px;}        .right{float: left;width: 400px;border: 3px solid darkblue;                padding-bottom: 2000px;margin-bottom: -2000px;}    </style>    </head>    <body>    <p class="container">    <p class="left">ger</p>    <p class="right">gr<br><br><br>rg</p>    <p style="clear:both"></p></p></body></html>

實現兩列布局

<!DOCTYPE html><html><head>    <style>        *{margin: 0;padding: 0;}        .container{width: 900px;border: 1px solid palevioletred;overflow: hidden;position: relative;}        .left{margin-right: 120px; border: 1px solid green;height: 300px;}        .right{float: right;width: 100px;border: 1px solid black;position: absolute;            top:0;right: 0;}        img{max-width: 100px;max-height: 100px;}    </style></head><body><p class="container">    <p class="left"></p>    <p class="right"><img src="4.jpg"/>    </p>    </p>   </body> </html>
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.