美文网首页
三栏布局的五种方式@令狐张豪

三栏布局的五种方式@令狐张豪

作者: 令狐张豪 | 来源:发表于2019-08-14 19:15 被阅读0次
flex方案
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
    html * {
        margin: 0;
        padding: 0;
    }

    .box {
        display: flex
    }

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

    .left {
        width: 300px;
        background: red;
    }

    .right {
        width: 300px;
        background: blue;
    }

    .center {
        background: yellow;
        flex: 1
    }
</style>

<body>
    <div class="box">
        <div class="left"></div>

        <div class="center">
            <h1>flex解决方案</h1>
            1.这是三栏布局中间部分
        </div>
        <div class="right"></div>
    </div>
</body>

</html>

table方案
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
    .box{
        width: 100%;
        height: 100px;
        display: table;
    }
    .left,.center,.right{
        display: table-cell
    }
    .left{
        width: 300px;
        background: red;
    }
    .center{
        background: yellow
    }
    .right{
        width: 300px;
        background: blue;
    }
</style>
<body>
    <div class="box">
        <div class="left"></div>
        <div class="center">
                <h1>table解决方案</h1>
                1.这是三栏布局中间部分
        </div>
        <div class="right"></div>
    </div>
</body>
</html>

浮动方案
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
    html * {
        padding: 0;
        margin: 0;
    }

    /* .article div{
        min-height: 100px;
    } */
    .left,
    .center,
    .right {
        height: 100px;
    }

    .left {
        width: 300px;
        background: red;
        float: left;
    }

    .right {
        width: 300px;
        background: blue;
        float: right;
    }

    .center {
        background: yellow
    }
</style>

<body>
    <div class="box">
        <div class="left"></div>
        <div class="right">

        </div>
        <div class="center">
            <h1>浮动解决方案</h1>
            1.这是三栏布局中间部分
        </div>
    </div>
</body>

</html>

绝对定位方案
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
    html * {
        padding: 0;
        margin: 0;
    }

    .left,
    .center,
    .right {
        height: 100px;
        position: absolute
    }
    .left{
        left: 0;
        width: 300px;
        background: red;
    }
    .right{
        right: 0;
        width: 300px;
        background: blue;
    }
    .center{
        left: 300px;
        right: 300px;
        background: yellow
    }
</style>

<body>
    <div class="box">
        <div class="left"></div>
        <div class="center">
            <h1>绝对定位解决方案</h1>
            1.这是三栏布局中间部分
        </div>
        <div class="right"></div>
    </div>
</body>

</html>

网格方案
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
    .box{
        display: grid;
        width: 100%;
        grid-template-rows: 100px;
        grid-template-columns: 300px auto 300px;
    }
</style>
<body>
    <div class="box">
        <div class="left"></div>
        <div class="center">
                <h1>网格解决方案</h1>
                1.这是三栏布局中间部分
        </div>
        <div class="right"></div>
    </div>
</body>
</html>

相关文章

网友评论

      本文标题:三栏布局的五种方式@令狐张豪

      本文链接:https://www.haomeiwen.com/subject/subnjctx.html