页面布局面试题

题目:假设高度已知,请写出三栏布局其中左右各300,中间自适应
在这里插入图片描述
这里有5种方法:浮动/弹性盒子/定位/表格布局/网格布局

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Layout</title>
    <!-- 页面布局:Layout -->
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .layout article div {
            height: 100px;
        }
        
        .layout .layout-left-center-right .left {
            width: 300px;
            float: left;
            background-color: coral;
        }
        
        .layout .layout-left-center-right .right {
            width: 300px;
            float: right;
            background-color: yellow;
        }
        
        .layout .layout-left-center-right .center {
            background-color: red;
            text-align: center;
        }
        /*  ----------------------------------------------------------------------------------------------- */
        
        .grad {
            height: 100px;
            width: 100%;
            display: flex;
            margin-top: 20px;
        }
        
        .left {
            width: 300px;
            background-color: red;
        }
        
        .right {
            width: 300px;
            background-color: yellowgreen;
        }
        
        .center {
            background-color: yellow;
            text-align: center;
            flex: 1;
        }
        /* 定位解决====================================================================================================================== */
        
        .layout_position article div {
            height: 100px;
            margin-top: 20px;
            position: absolute;
        }
        
        .layout_position-left-center-right .left {
            width: 300px;
            left: 0px;
            background-color: burlywood;
        }
        
        .layout_position-left-center-right .right {
            width: 300px;
            right: 0px;
            background-color: black;
        }
        
        .layout_position-left-center-right .center {
            left: 300px;
            right: 300px;
            background-color: firebrick;
        }
        /* ============================================================================================================ */
        
        .table_t {
            height: 100px;
            width: 100%;
            display: table;
            margin-top: 150px;
        }
        
        .table_t div {
            display: table-cell;
        }
        
        .table_t .left {
            width: 300px;
            background-color: blanchedalmond;
        }
        
        .table_t .right {
            width: 300px;
            background-color: firebrick;
        }
        
        .table_t .center {
            background-color: yellow;
        }
        /* ================================================================================================================================================== */
        
        .grid .grid_g {
            margin-top: 20px;
            display: grid;
            width: 100%;
            grid-template-rows: 100px;
            grid-template-columns: 300px auto 300px;
        }
        
        .grid_g .left {
            background-color: yellow;
        }
        
        .grid_g .center {
            background-color: green;
        }
        
        .grid_g .right {
            background-color: gold;
        }
    </style>
</head>

<body>
    <section class="layout">
        <article class="layout-left-center-right">
            <div class="left"></div>
            <div class="right"></div>
            <div class="center">
                <h2>浮动布局</h2>
            </div>
        </article>
    </section>
    <!-- ......................................................................................................................... -->
    <div class="grad">
        <div class="left"></div>
        <div class="center">
            <h2>flexbox布局</h2>
        </div>
        <div class="right"></div>
    </div>
    <!-- ============================================================================================================================== -->
    <section class="layout_position">
        <article class="layout_position-left-center-right">
            <div class="left"></div>
            <div class="center">
                <h2>绝对定位布局</h2>
            </div>
            <div class="right"></div>
        </article>
    </section>
    <!-- ========================================================================================================================= -->
    <section class="table">
        <article class="table_t">
            <div class="left"></div>
            <div class="center">
                <h2>表格布局解决方案</h2>
            </div>
            <div class="right"></div>
        </article>
    </section>
    <!-- ========================================================================================================================= -->
    <section class="grid">
        <article class="grid_g">
            <div class="left"></div>
            <div class="center">
                <h2>网格布局解决方案</h2>
            </div>
            <div class="right"></div>
        </article>
    </section>
</body>

</html>

效果:
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值