今天才知道原来position加上上下左右可以控制的到div的宽度的

比如我现在有一个需要

position+left+bottom+top+right

这样一个需求

现在是红色部分50px

但是你可能不知道剩下的蓝色部分的高度是多少

蓝色部分要怎么填满剩余的高度呢 这时候left,right,top,bottom,就很有用了

 

直接给蓝色的div:position:absolute;top:50px;bottom:0;left:0;right:0

给这个样式蓝色部分就填满了除了红色部分的高度跟宽度了

 

然后黄色部分要在蓝色部分里面水平垂直居中,那网上就有很多方案了

 

 

 

 

要解决这个问题还有一个方案

<div style="display: flex;flex-direction: column;height: 100vh">
<div style='height:50px;background-color: red'></div>
<div style='flex: 1;background-color: blue;display: flex;justify-content: center;align-items: center;'>
<div style='height:50px;width:50px;background-color: yellow;'></div>
</div>
</div>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2021-12-16
  • 2022-01-02
  • 2022-03-07
  • 2020-04-25
  • 2021-06-22
猜你喜欢
  • 2021-09-18
  • 2021-11-13
  • 2021-09-01
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案