两栏布局和三栏布局的方式常见的

两栏布局的方式左边定宽,右边自适应

实现方式

     1 margin-left  float  

     2   display: flex;    flex: 1;

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    /* 第一个  */
    .left {
        width: 200px;
        height: 200px;
        background-color: red;
        float: left;
    }

    .right {
        height: 200px;
        margin-left: 200px;
        background-color: rgb(21, 204, 113);
    }

    .box {
        overflow: hidden;
    }

    /* 第二个 */
    .boxs {
        width: 100%;
        height: 200px;
        display: flex;
    }

    .lefts {
        width: 200px;
        height: 100%;
        background-color: rgb(31, 190, 39);
    }

    .rights {
        flex: 1;
        background-color: aqua;
    }
</style>

<body>
    <!-- 第一个 -->
    <div class="box">
        <div class="left">

        </div>
        <div class="right">

        </div>
    </div>
    <!-- 第二个 -->
    <div class="boxs">
        <div class="lefts">

        </div>
        <div class="rights">

        </div>
    </div>
</body>

</html>

 三栏布局、(圣杯布局、双飞翼布局) 中间自适应两边固定

实现方式

       1 position 

       2  float + margin

       3  display: grid;   grid-template-columns: 300px auto 300px;

  还有好多 flex ....

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    /* 第一种  */
    .box {
        position: relative;
        height: 100%;
        width: 100%;
    }

    .a,
    .b,
    .c {
        height: 200px;
        line-height: 200px;
        text-align: center;
    }

    .a {
        position: absolute;
        right: 0;
        top: 0;
        width: 100px;
        background-color: red;
    }

    .b {
        position: absolute;
        left: 0;
        top: 0;
        width: 100px;
        background-color: pink;
    }

    .c {
        margin: 0 100px;
        background-color: rgb(19, 44, 171);
    }

    /* 第二种 */

    .boxs {
        width: 100%;
        height: 100%;
    }

    .as,
    .bs,
    .cs {
        height: 200px;
        line-height: 200px;
    }

    .as {
        float: right;
        width: 200px;
        background-color: blue;
    }

    .bs {
        float: left;
        width: 200px;
        background-color: pink;
    }

    .cs {
        margin: 0 200px 0 200px;
        background-color: orange;
    }

    /* 第三种 */
    .boxa {
        width: 100%;
        height: 100%;
        display: grid;
        /* 重点 */
        grid-template-columns: 300px auto 300px;
    }

    .left,
    .right,
    .center {
        height: 200px;
    }

    .left {
        background-color: pink;
    }

    .right {
        background-color: rgb(198, 44, 44);
    }

    .center {
        background-color: rgb(47, 218, 187);
    }
</style>

<body>
    <!-- 第一种 -->
    <div class="box">
        <div class="a"></div>
        <div class="b"></div>
        <div class="c"></div>
    </div>
    <!-- 第二种 -->
    <div class="boxs">
        <div class="as"></div>
        <div class="bs"></div>
        <div class="cs"></div>
    </div>
    <!-- 第三种 -->
    <div class="boxa">
        <div class="left"></div>
        <div class="right"></div>
        <div class="center"></div>
    </div>
</body>

</html>

猜你喜欢

转载自blog.csdn.net/qq_54753561/article/details/124085763