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;
            }

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

  • 相关阅读:
    如何监控Android应用的网络性能
    进程、线程和协程的区别
    微服务
    码农和规矩
    Java才是世界上最好的语言,Java在高频交易中替代C++
    微服务
    int.Parse()与int.TryParse()
    Json的序列化和反序列化
    .NET 垃圾回收与内存泄漏
    ASP.NET(C#)连接数据库和操作数据库
  • 原文地址:https://www.cnblogs.com/ilaozhao/p/9200880.html
Copyright © 2011-2022 走看看