• 左边固定,右边自适应解决方案


    1 首先利用浮动

    给左边设置宽度,高度,浮动为left

    右边不写宽度,给高度,给margin-left设置左边容器的宽度,撑开

    因为div属于块级元素会自动占满一行

    <!DOCTYPE html>
    
    <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>
        .left {
          width: 200px;
          height: 100px;
          background: blueviolet;
        }
    
        .right {
          background: goldenrod;
          height: 100px;
        }
    
        .l {
          float: left;
        }
    
        .r {}
      </style>
    </head>
    
    <body>
      <div>
        <div class="left l">固定200px</div>
        <div class="right r">自动充满</div>
      </div>
    </body>
    <script>
    
    </script>
    
    </html>

    2 利用定位

    父级设置相对定位

    左右设置为绝对定位,右边的设置为宽度百分之百,开启怪异盒子,padding-left设置为左边的宽度,

    重点左边的设置z-index为1,浮动在右边的上边

    <!DOCTYPE html>
    
    <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>
        .left {
          width: 200px;
          height: 100px;
          background: blueviolet;
        }
    
        .right {
          background: goldenrod;
          height: 100px;
        }
    
        .l {
          position: absolute;
          z-index: 1;
        }
    
        .r {
          position: absolute;
          right: 0;
          top: 0;
          width: 100%;
          padding-left: 200px;
          box-sizing: border-box;
        }
      </style>
    </head>
    
    <body>
      <div style="position: relative;">
        <div class="left l">固定200px</div>
        <div class="right r">自动充满</div>
      </div>
    </body>
    <script>
    
    </script>
    
    </html>

    3利用弹性盒子

    <!DOCTYPE html>
    
    <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>
        .left {
          width: 200px;
          height: 100px;
          background: blueviolet;
        }
    
        .right {
          background: goldenrod;
          height: 100px;
        }
    
        .l {}
    
        .r {
          flex: 1;
        }
      </style>
    </head>
    
    <body>
      <div style="display: flex;">
        <div class="left l">固定200px</div>
        <div class="right r">自动充满</div>
      </div>
    </body>
    <script>
    
    </script>
    
    </html>
  • 相关阅读:
    WebService-CXF 学习笔记
    Java中对于ClassLoader类加载器 嵌套了深度技术的价值
    WebService学习笔记
    MongoDB学习笔记
    java.io.IOException: java.io.FileNotFoundException: /tmp/tomcat.2457258178644046891.8080/work/Tomcat/localhost/innovate-admin/C:/up/154884318438733213952/sys-error.log (没有那个文件或目录)
    Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime
    Mysql优化
    SI架构设计与实践
    高并发高可用处理大数据量
    虚拟机安装CentOS详细操作
  • 原文地址:https://www.cnblogs.com/skydragonli/p/11669142.html
Copyright © 2020-2023  润新知