zoukankan      html  css  js  c++  java
  • html基本布局1---div嵌套布局

    需求:div3 宽100R% ,高100px,内部包含div1和div2; div1 宽100px,高100px, 如何使div2宽度充满剩余空间(尽量使用css实现)

    解决方案1---弹性盒布局:

            .div3{
                width: 100%;
                height: 100px;
                display: flex;
            }
            .div1{
                width: 100px;
                height: 100px;
                background-color: bisque;
            }
            .div2{
                flex: 1;
                height: 100px;
                background-color: #aaaaaa;
            }

    解决方案2---CSS3新属性 calc

            .div3{
                width: 600px;
                height: 100px;
            }
            .div1{
                float:left;
                width: 100px;
                height: 100px;
                background-color: bisque;
            }
            .div2{
                float:left;
                width:calc(100% - 100px);
                height: 100px;
                background-color: #aaaaaa;
            }

    兼容性参考:

    解决方案3---定位+margin:

            .div3{
                text-align: center;
                line-height: 100px;
                width: 100%;
                height: 100px;
            }
            .div1{
                position: absolute;
                left: 0;
                width: 100px;
                height: 100px;
                background-color: bisque;
            }
            .div2{
                margin-left: 100px;
                height: 100px;
                background-color: #aaaaaa;
            }

    解决方案4---定位+box-sizing:

            .div3{
                text-align: center;
                line-height: 100px;
                width: 100%;
                height: 100px;
                box-sizing: border-box;
                padding-left: 100px;
            }
            .div1{
                position: absolute;
                left: 0;
                width: 100px;
                height: 100px;
                background-color: bisque;
            }
            .div2{
                width: 100%;
                height: 100px;
                background-color: #aaaaaa;
            }

    如有其他更好的方案,不吝赐教~

  • 相关阅读:
    JS 随机整数
    微信小程序 功能函数 支付接口
    JS 正则表达式
    JS 日期 自动补齐 “2017-11-22 14:43”
    schema get_ddl
    StringBuffer 清空
    java中split任意数量的空白字符
    美国法官工资
    纪检委,检察院的工资
    国家司法机构
  • 原文地址:https://www.cnblogs.com/ilaozhao/p/9200880.html
Copyright © 2011-2022 走看看