小编Fin*_*nnb的帖子

使用可变高度的周围元素最大化div的高度

我有一个div,我希望最大化,在父母的基础上100vh.

问题是我有两个pdiv,它们也可以根据窗口的宽度改变它们的高度,从而导致不同的大小.

现在,快速和肮脏的解决方案可能只是运行一个jQuery片段检测母体的大小div以及p基于这些div,并设置div的高度上运行的功能doc.readywindow.onresize.

但这感觉不必要,我想知道是否有一个更简洁的解决方案只使用我不知道的CSS?

我已经在下面设置了一个简化但不起作用的问题版本,看看你是否能比我所指的更清楚.

任何提示都会很棒,谢谢!

*{
  margin: 0;
  padding: 0;
  font-family: Arial, san-serif;
}

#parent{
  height: 100vh;
  background: lightblue;
}

p{
  font-size: 40px; 
  background: yellow;
 }

#p1{
  top: 0;
}

#p2{
  bottom: 0;
  position: absolute;
}

div{
  background-color: red;
  height: 100%;
}
Run Code Online (Sandbox Code Playgroud)
<div id="parent">
  <p id="p1">Long block that only appears on the top</p>
  <div>Maximising Div</div>
  <p id="p2">Long block that only appears on the bottom</p>
</div>
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery css3

6
推荐指数
1
解决办法
140
查看次数

标签 统计

css ×1

css3 ×1

html ×1

javascript ×1

jquery ×1