美文网首页
[HZH001]黄子涵的第一次前端面试

[HZH001]黄子涵的第一次前端面试

作者: 黄子涵 | 来源:发表于2022-03-21 01:38 被阅读0次

    公司概况

    爱企查

    爱企查

    职友集

    职友集

    看准网

    看准网

    面试题目

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

    三栏布局

    浮动方式实现三栏布局

    源码
    <!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>
    
    效果

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

    相关文章

      网友评论

          本文标题:[HZH001]黄子涵的第一次前端面试

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