• html+css 常用布局


    1.中间固定宽度,两侧自适应 
    1.1
    flex布局
    <!DOCTYPE html>
    <html lang="en">

    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
    html,body,div{
    height: 100%;
    }
    .left {
    background-color: #ccc;
    flex:1;
    }

    .middle {
    background-color: #75cc23;
    flex:0 0 400px;
    }

    .right {
    background-color: #cc3b38;
    flex:1;
    }
    .con{
    display: flex;
    justify-content: center;
    }
    </style>
    </head>
    <body>
    <div class="con">
    <div class="left">

    </div>
    <div class="middle">

    </div>
    <div class="right">

    </div>
    </div>

    </body>

    //也可以用这个样式
    html,body,div{
    height: 100%;
    }
    .left {
    background-color: #ccc;
    flex-grow:1;
    }

    .middle {
    background-color: #75cc23;
    400px;
    }

    .right {
    background-color: #cc3b38;
    flex-grow:1;
    }
    .con{
    display: flex;
    justify-content: center;
    }


    1.2 calc+float

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

    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
    html,body,div{
    height: 100%;
    }
    .left,.right {
    background-color: #ccc;
    float: left;
    calc((100% - 400px) / 2)
    }

    .middle {
    background-color: #75cc23;
    400px;
    float:left;
    }

    .right {
    background-color: #cc3b38;

         }
    </style>
    </head>
    <body>
    <div class="con">
    <div class="left">

    </div>
    <div class="middle">

    </div>
    <div class="right">

    </div>
    </div>

    </body>
    </html>

    2.两边固定 中间自适应
    2.1浮动布局
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>title</title>
    <style type="text/css">
    .con div{
    min-height: 200px;
    }
    .con .left{
    float: left;
    300px;
    background: #72f5ff;
    }
    .con .right{
    float: right;
    300px;
    background: #7aff73;
    }
    .con .middle{
    background: #ff2d21;
    }

    </style>
    </head>
    <body>

    <div class="con">
    <div class="left"></div>
    <div class="right"></div>
    <div class="middle">

    </div>
    </div>

    </body>
    </html>
    2.2使用绝对定位
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>绝对定位布局</title>
    <style type="text/css">
    .con div{
    position: absolute;
    min-height: 200px;
    }
    .con .left{
    left: 0;
    300px;
    background: red;
    }
    .con .right{
    right: 0;
    300px;
    background: blue;
    }
    .con .middle{
    left: 300px;
    right: 300px;
    background: pink;
    }

    </style>
    </head>
    <body>

    <div class="con">
    <div class="left"></div>
    <div class="middle">

    </div>
    <div class="right"></div>
    </div>

    </body>
    </html>
    2.3 flex布局
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>flex</title>
    <style type="text/css">
    .con{
    min-height: 200px;
    display: flex;
    }
    .con .left{
    300px;
    background: red;
    }
    .con .right{
    300px;
    background: blue;
    }
    .con .middle{
    flex-grow: 1;
    background: #ffa861;
    }

    </style>
    </head>
    <body>

    <div class="con">
    <div class="left"></div>
    <div class="middle">
    </div>
    <div class="right"></div>
    </div>

    </body>
    </html>




  • 相关阅读:
    在国内时,更新ADT时需要配置的
    mantis增加密码修改
    http://182.92.241.20/mypro/login 偶的点金项目细化分包管理平台即将上线!!
    bootstrap菜单完美解决---原创
    PB常用日期
    ctrl+shift+del 清理火狐缓存,解决页面显示错乱问题
    Kylin上chromium不能用flash的解决命令
    正确的SVN导入代码命令
    GNU :6.47 Function Names as Strings
    std::advance 给迭代器增加指定偏移量
  • 原文地址:https://www.cnblogs.com/-youth/p/11646843.html
Copyright © 2020-2023  润新知