定寬+流動佈局

<!DOCTYPE html>
<html>
<head>
    <style>
        aside{
            width: 200px;
            height: 200px;
            background: #5A6A94;
        }
        section{
            height: 200px;
            background: #BE4F4F;
        }
    </style>
</head>
<body>
<div class="container">
    <aside class="left">Left</aside>
    <section class="right">right</section>
</div>
</body>
</html>

這裏寫圖片描述

左邊設置左浮動,右邊寬度設置100%

不需要設置右邊寬度100%也可以實現這樣的效果,塊級元素默認寬度爲100%

<!DOCTYPE html>
<html>
<head>
    <style>
        aside{
            width: 200px;
            height: 200px;
            background: #5A6A94;
            float: left;
        }
        section{
            height: 200px;
            background: #BE4F4F;
            width: 100%;
        }
    </style>
</head>
<body>
<div class="container">
    <aside class="left">Left</aside>
    <section class="right">right</section>
</div>
</body>
</html>

這裏寫圖片描述

父容器設置 display:flex;right部分設置 flex:1

<!DOCTYPE html>
<html>
<head>
    <style>
        .container{
            display: flex;
        }
        aside{
            width: 200px;
            height: 200px;
            background: #5A6A94;
        }
        section{
            height: 200px;
            background: #BE4F4F;
            flex: 1;

        }
    </style>
</head>
<body>
<div class="container">
    <aside class="left">Left</aside>
    <section class="right">right</section>
</div>
</body>
</html>

使用負margin

<!DOCTYPE html>
<html>
<head>
    <style>
        .container{
            float: left;
            width: 100%;
        }
        aside{
            width: 200px;
            height: 200px;
            background: #5A6A94;
        }
        section{
            height: 200px;
            background: #BE4F4F;
        }
        .right{margin-left: 200px;}
        .left{
            float: left;
            margin-left: -100%;
        }
    </style>
</head>
<body>
<div class="container">
    <section class="right">right</section>
</div>
    <aside class="left">Left</aside>

</body>
</html>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        .content{
            width: 100%;
            height: 200px;
            background-color: #00ccff;
            float: left;
        }
        .right{
            margin-left: 200px;
        }
        .left{
            width: 200px;
            height: 200px;
            background-color: #8A0E00;
            float: left;
            margin-left: -100%;
        }
    </style>
</head>
<body>
<div class="content">
    <div class="right">right</div>
</div>
<div class="left">left</div>

</body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章