zoukankan      html  css  js  c++  java
  • 高度已知,左右定宽,中间自适应三栏布局的五种写法

    1.使用浮动布局

    <!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>
        <style>
    
            *{
                margin: 0;
                padding: 0;
            }
    
            .box>div{
                height: 100px;
            }
    
            .box .left{
                background-color: red;
                 300px;
                float: left;
            }
    
            .box .right{
                background-color: blue;
                 300px;
                float: right;
            }
    
            .box .center{
                text-align: center;
                line-height: 100px;
                color: #fff;
                background-color: orange;
            }
        </style>
    </head>
    <body>
        
        <div class="box">
            <div class="left"></div>
            <div class="right"></div>
            <div class="center">第一种方法:浮动</div>
        </div>
    
    </body>
    </html>
    

    2.使用定位布局

    <!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>
        <style>
    
            *{
                margin: 0;
                padding: 0;
            }
    
            .box>div{
                height: 100px;
                position: absolute;
            }
    
            .box .left{
                background-color: red;
                 300px;
                left: 0;
            }
    
            .box .right{
                background-color: blue;
                 300px;
                right: 0;
            }
    
            .box .center{
                text-align: center;
                line-height: 100px;
                color: #fff;
                background-color: orange;
                left: 300px;
                right: 300px;
            }
        </style>
    </head>
    <body>
        
        <div class="box">
            <div class="left"></div>
            <div class="center">第二种方法:定位</div>
            <div class="right"></div>
        </div>
    
    </body>
    </html>
    

    3.使用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>
        <style>
    
            *{
                margin: 0;
                padding: 0;
            }
    
            .box{
                display: flex;
            }
    
            .box>div{
                height: 100px;
            }
    
            .box .left{
                background-color: red;
                 300px;
            }
    
            .box .right{
                background-color: blue;
                 300px;
            }
    
            .box .center{
                text-align: center;
                line-height: 100px;
                color: #fff;
                background-color: orange;
                
                flex: 1;
            }
        </style>
    </head>
    <body>
        
        <div class="box">
            <div class="left"></div>
            <div class="center">第三种方法:flexbox布局</div>
            <div class="right"></div>
        </div>
    
    </body>
    </html>
    

    4.使用表格布局

    <!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>
        <style>
    
            *{
                margin: 0;
                padding: 0;
            }
    
            .box{
                display: table;
                 100%;
                height: 100px;
            }
    
            .box>div{
                display: table-cell;
            }
    
            .box .left{
                background-color: red;
                 300px;
            }
    
            .box .right{
                background-color: blue;
                 300px;
            }
    
            .box .center{
                text-align: center;
                line-height: 100px;
                color: #fff;
                background-color: orange;
            }
        </style>
    </head>
    <body>
        
        <div class="box">
            <div class="left"></div>
            <div class="center">第四种方法:表格布局</div>
            <div class="right"></div>
        </div>
    
    </body>
    </html>
    

    5.使用网格布局

    <!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>
        <style>
    
            *{
                margin: 0;
                padding: 0;
            }
    
            .box{
                display: grid;
                 100%;
                grid-template-rows: 100px;
                grid-template-columns: 300px auto 300px;
            }
    
            .box .left{
                background-color: red;
            }
    
            .box .right{
                background-color: blue;
            }
    
            .box .center{
                text-align: center;
                line-height: 100px;
                color: #fff;
                background-color: orange;
            }
        </style>
    </head>
    <body>
        
        <div class="box">
            <div class="left"></div>
            <div class="center">第五种方法:网格布局</div>
            <div class="right"></div>
        </div>
    
    </body>
    </html>
    
  • 相关阅读:
    Android事件机制之一:事件传递和消费
    Android单个控件占父控件宽度一半且水平居中
    Android IllegalArgumentException: Cannot draw recycled bitmaps解决方法
    Android视图篇之一:Android常见基本布局
    Android Nine-patch(.9.png)小结
    adb server is out of date. killing... ADB server didn't ACK解决方法
    Docker 下自定义安装 Tomcat
    Docker 删除 images
    SecureCRT 取消右击粘贴功能
    如何将不同业务模块产生的日志 分多文件记录
  • 原文地址:https://www.cnblogs.com/fangfeiyue/p/7392673.html
Copyright © 2011-2022 走看看