-3
Im在一行中显示3个div框,但我希望它们的高度为100%。当我使用绝对位置和高度100%。该盒子然后到100%,但他们堆叠在一起。但我希望他们彼此相邻。CSS高度100%无绝对位置
Im在一行中显示3个div框,但我希望它们的高度为100%。当我使用绝对位置和高度100%。该盒子然后到100%,但他们堆叠在一起。但我希望他们彼此相邻。CSS高度100%无绝对位置
为了让div的高度达到100%,您必须将body和html height设置为100%。
相反,您可以考虑使用视口宽度。要使它们并排考虑使用display:flex。
检查下面的代码片段
div {
height: 100vh;
width:60vw;
}
div:nth-child(1) {
background: green;
}
div:nth-child(2) {
background: red;
}
div:nth-child(2) {
background: pink;
}
.container {
display: flex;
justify-content: space-between;
}
<div class="container">
<div>
</div>
<div>
</div>
<div>
</div>
</div>
希望它可以帮助什么
我想补充说,任何百分比高度元素都需要它的父元素有一个高度集或它不起作用。这意味着如果您的百分比高度元素不是'body'的子元素,那么在'html'和'body'上设置'height:100%;'不起作用。 – hungerstar
100%的高度?父元素?视口? – hungerstar
@InvolveX你可以使用像http://codepen.io/pen/这样的工具来创建一个演示来帮助说明你的问题 –