其他分享
首页 > 其他分享> > 【HZH001】黄子涵的第一次前端面试

【HZH001】黄子涵的第一次前端面试

作者:互联网

公司概况

爱企查

爱企查

职友集

职友集

看准网

看准网

面试题目

如何实现中间空白,左右布局?

三栏布局

浮动方式实现三栏布局

源码
<!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>浮动方式实现三栏布局</title>
    <style>
        * {
            height: 100%;
            padding: 0;
            margin: 0;
        }

        .left {
            float: left;
            height: 100%;
            background: red;
        }

        .right {
            float: right;
            height: 100%;
            background: green;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="left">左边</div>
        <div class="right">右边</div>
    </div>
</body>

</html>
效果

使用浮动方式实现三栏布局

绝对定位实现三栏布局

<!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>绝对定位方式实现三栏布局</title>
    <style>
        * {
            height: 100%;
            padding: 0;
            margin: 0;
        }

        .left {
            left: 0;
            height: 100%;
            background: red;
            position: absolute;
        }

        .right {
            right: 0;
            height: 100%;
            background: blue;
            position: absolute;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="left">左边</div>
        <div class="right">右边</div>
    </div>
</body>

</html>
效果

使用绝对定位实现三栏布局

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>flex弹性盒子实现三栏布局</title>
    <style>
        * {
            height: 100%;
            padding: 0;
            margin: 0;
        }

        .container {
            display: flex;
            justify-content: space-between;
        }

        .left {
            height: 100%;
            background: red;
        }

        .right {
            height: 100%;
            background: blue;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="left">左边</div>
        <div class="right">右边</div>
    </div>
</body>

</html>
效果

使用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>表格布局实现三栏布局</title>
    <style>
        * {
            height: 100%;
            width: 100%;
            padding: 0;
            margin: 0;
        }

        .container {
            display: table;
        }

        .container > div {
            display: table-cell;
        }

        .left {
            width: 300px;
          background: red;
        }
        
        .right {
            width: 300px;
          background: blue;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="left">左边</div>
        <div class="center"></div>
        <div class="right">右边</div>
    </div>
</body>

</html>
效果

使用表格布局实现三栏布局

标签:黄子涵,right,background,100%,布局,HZH001,height,面试,三栏
来源: https://www.cnblogs.com/Huang-zihan/p/16032989.html