CSS布局

CSS布局(浮动布局、绝对定位、flexBox、table-cell、grid网格布局)

有这么个题目:
在这里插入图片描述

实现的效果:
在这里插入图片描述
拉伸后还是能自适应
在这里插入图片描述

代码

代码片.

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8">
        <title>layout</title>
        <style media="screen">
            html *{
                padding: 0;
                margin: 0;
            }
            .layout article div{
                height: 100px;
            }
            .layout{
                margin-top: 20px;
            }
        </style>
    </head>
    <body>

        <setion class="layout float">
            <style>
                .layout.float .left{
                    float:left;
                    width: 300px;
                    background: red;
                }
                .layout.float .center{
                    background: yellow;
                }
                .layout.float .right{
                    float: right;
                    width: 300px;
                    background: blue;
                }
            </style>
            <article class="left-center-right">
                <div class="left"></div>
                <div class="right"></div>
                <div class="center">
                    <h1>浮动中间部分</h1>
                </div>
            </article>
        </setion>

        <section class="layout absolute">
            <style>
                .layout.absolute div{
                    position: absolute;
                }
                .layout.absolute .left{
                    left:0;
                    background: red;
                    width: 300px;
                }
                .layout.absolute .center{
                    left:300px;
                    right:300px;
                    background: yellow;
                }
                .layout.absolute .right{
                    right: 0;
                    background: blue;
                    width: 300px;
                }
            </style>
            <article class="left-center-right">
                <div class="left"></div>
                <div class="center">
                    <h1>绝对定位中间部分</h1>
                </div>
                <div class="right"></div>
            </article>
        </section>

        <section class="layout flex">
            <style>
                .layout.flex .left-center-right{
                    margin-top: 140px;
                    display: flex;
                }
                .layout.flex .left{
                    background: red;
                    width: 300px;
                }
                .layout.flex .center{
                    flex:1;
                    background: yellow;
                }
                .layout.flex .right{
                    background: blue;
                    width: 300px;
                }
            </style>
            <article class="left-center-right">
                <div class="left"></div>
                <div class="center">
                    <h1>flexBox中间部分</h1>
                </div>
                <div class="right"></div>
            </article>
        </section>


        <section class="layout table-cell">
            <style>
                .layout.table-cell .left-center-right{
                    width: 100%;
                    display: table;
                    height: 100px;
                }
                .layout.table-cell .left-center-right>div{
                    display: table-cell;
                }
                .layout.table-cell .left{
                    background: red;
                    width: 300px;
                }
                .layout.table-cell .center{
                    background: yellow;
                }
                .layout.table-cell .right{
                    background: blue;
                    width: 300px;
                }
            </style>
            <article class="left-center-right">
                <div class="left"></div>
                <div class="center">
                    <h1>table-cell中间部分</h1>
                </div>
                <div class="right"></div>
            </article>
        </section>


        <section class="layout grid">
            <style>
                .layout.grid .left-center-right{
                    width: 100%;
                    display: grid;
                    grid-template-rows: 100px;
                    grid-template-columns: 300px auto 300px;
                }

                .layout.grid .left{
                    background: red;
                }
                .layout.grid .center{
                    background: yellow;
                }
                .layout.grid .right{
                    background: blue;
                }
            </style>
            <article class="left-center-right">
                <div class="left"></div>
                <div class="center">
                    <h1>grid中间部分</h1>
                </div>
                <div class="right"></div>
            </article>
        </section>


    </body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值