安装设置
.container {
position: relative;
display: flex;
flex-direction: row;
justify-content: flex-start;
flex: 1 1;
padding: 28px;
width: 100%;
background-color: #eee;
}
.bar {
position: relative;
width: 5px;
background-color: blue;
}
<div class="container">
<div class="bar"></div>
<div>
lskdjf
</div>
</div>
请注意,蓝色的条达到容器的最大高度,除去填充部分。
但是,如果我在 .bar
类中添加 height: 100%
,则高度将消失。
.bar {
position: relative;
width: 5px;
background-color: blue;
height: 100%;
}
问题
我想实际将高度设置为100%会使浏览器混淆,因为父元素实际上没有设置高度,但是预先设置高度为100%的属性允许高度达到100%吗?考虑到这实际上是我的目标,只是不指定100%是否“正确”,或者是否有更好的方法确保.bar
元素达到完整高度?