左邊寬度固定,右邊寬度自適應的三種寫法

htmlcss

<div class='demo'>
        <div class="left">left</div>
        <div class="right">right</div>
    </div>

公用css:html

 .left {
        width: 200px;
        background-color: red;
    }

    .right {
        width: 100%;
        height: 200px;
        background-color: blue;
    }

1 利用css3   flexcss3

css:flex

 .demo{
        display: flex;
    }
    .demo .right{
        flex:1;
    }

2 左邊浮動spa

.demo{
        overflow: hidden;
        
    }
    .demo .left{
        float: left;
    }

3 左右都浮動 使用calc計算右邊的寬度code

.demo{
        overflow: hidden;
    }
    .demo .left{
        float: left;
    }
    .demo .right{
      float: left;
      width: calc(100% - 200px);
    }

  使用css3 flex,還能夠實現,左邊的高度隨右邊的高度而變化;htm

相關文章
相關標籤/搜索