css 百分比的html高度似乎不起作用[duplicate]

vi4fp9gy  于 2022-12-05  发布在  其他
关注(0)|答案(1)|浏览(148)

此问题在此处已有答案

Percentage Height HTML 5/CSS(7个答案)
2天前关闭。
我期望〈div style=“height:50%;背景色:青色;“在屏幕上画一个蓝色的方框。但是它没有。只有我用字符填充的区域变成蓝色。那么我是如何画一个彩色的方框,比如说父级的可见高度的33%呢?我似乎记得它在某个时候确实工作过,但是我不记得它是如何做的了。保罗

<html>
<style>
.worksOK {
  background-color: cyan;
}
.DoesntWork {
  background-color: lightblue;
}
</style>
<body>
<h1>Height % doesn't seem to work</h1>
<div class = "worksOK" style="height:75px;">
  A fixed height, like <b>height:50px;</b> works fine
</div>
<div class = "DoesntWork" style="height:75%;">
  But a height in percentage, like <b>height:50%;</b> doesn't seem to work.
</div>
<br>It does however work in this demo:<a href="https://www.w3schools.com/cssref/playdemo.php?filename=playcss_height">w3schools</a><br><br>Unfortunately I cannot access the css code, so I do not understand why that is.<br>
And I cannot recall ever have been able to make height work with a percentage.

</body>
</html>```
wgeznvg7

wgeznvg71#

为容器添加一个高度,例如,我在这里为主体添加100vh(视口高度
第一个

相关问题