css 實現左右布局


  <div class="test-layout">
        <p></p>
        <p></p>
  </div>

 

1. position定位

.test-layout {
        position: relative;
 }

p:last-child{
        position: absolute;
        right: '設定你要的距離' ;
        top: '設定你要的距離';
}

 

2. 使用-webkit-box彈性盒子布局,使用ie8+,Chrome,火狐,同時使用移動

.test-layout {
        position: -webkit-box;
        -webkit-box-orient: horizontal;
 }

p{
        -webkit-box-flex: 1;  // 可自定義寬度
}    

 

3. table布局

<table>
    <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
        <td>4</td>
    </tr>
</table>

 

4. display:inline-block

p{
     display: inline-block;
 }

 

5. float

float+margin: 固定左邊,右邊拉開距離

p: first-child{
    float: left;
    width: 200px;
    height: 100%;
}
p: last-child{
    margin-left: 200px;
}

float+overflow: 固定左邊,利用overflow:hidden形成BFC,不會與float重疊

p: first-child{
    float: left;
    width: 200px;
    height: 100%;
}
p: last-child{
    overflow:hidden;
}

float+calc: 固定左邊,減掉左邊寬度

p: first-child{
    float: left;
    width: 200px;
    height: 100%;
}
p: last-child{
    width:calc(100%-200px);
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM