zoukankan      html  css  js  c++  java
  • css 左侧高度 跟随右侧内容高度 自适应

    1,flex布局

    flex布局的中align-items的stretch属性可以让内部元素高度铺满。CSS代码如下:

    /*flex布局*/
      .parent{
         display: flex;
         justify-content: space-between;
         align-items: stretch;
       }
       .left{
         background: red;
       }
       .right{
         margin-left: 110px;
         background: blue;
       }

     2.position

    给父元素设置position:relative,左边的子元素设置position:absulote,且左边元素的高度为100%。CSS代码如下:

    /*position*/
    .left{
      height: 100%;
      width: 100px;
      background: red;
      position: absolute;
    }
    .right{
      width: 300px;
      margin-left: 110px;
      background: blue;
    }
    .parent{
      position: relative;
    }

    3、margin负值

    这种方法的原理其实是把子元素的实际高度撑开的很多,父元素overflow:hidden起到一个遮罩作用,来保持左右两侧元素高度相等的。css代码如下

    /*margin负值*/
    .parent{
      overflow: hidden;
    }
    .left,.right{
      margin-bottom: -5000px;
      padding-bottom: 5000px;
    }
    .left{
      float: left;
      background: red;
    }
    .right{
      float: right;
      background: blue;
    }
  • 相关阅读:
    python 代码片段17
    python 代码片段15
    python 代码片段14
    python 代码片段13
    python 代码片段12
    RBAC模型
    2、服务注册与发现-电影服务
    1、通过eureka创建注册中心
    prop与attr
    位运算,效率高
  • 原文地址:https://www.cnblogs.com/lq2333/p/14907132.html
Copyright © 2011-2022 走看看