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

 

这种方法的原理其实是把子元素的实际高度撑开的很多,父元素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;
}

 

相关文章:

  • 2022-02-09
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2022-03-06
  • 2022-02-09
  • 2022-02-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
  • 2021-08-30
  • 2022-12-23
相关资源
相似解决方案