CSS - 容器高度与父级 div 高度相同,除非父级 div 小于容器 div
CSS - Container height same height as parent div unless parent div is smaller than container div
我目前得到父 div 高度:height: inherit;,但是当我缩小 window 时,父 div 小于容器 div 所以溢出:隐藏;隐藏一半的容器内容。
是否可以只用 css 做到这一点?
这是代码:
<div id="container">
<div class="content">
<div class="wrapper">
Content here
</div>
</div>
#container {
float: left;
height: 400px;
width: 400px;
background-color: red;
}
.content {
float: left;
height: inherit;
width: 90%;
overflow: hidden;
position: relative;
background-color: black;
}
.wrapper {
width: 90%;
height: 900px;
position: relative;
z-index: 99;
background-color: blue;
}
您可能使用 overflow
属性 来清除浮动,对吗?
然后将overflow: hidden
改为overflow: auto
。
设置内容div最小高度:400px; (替换高度)所以它永远不会小于容器,但可以根据需要变大。
我目前得到父 div 高度:height: inherit;,但是当我缩小 window 时,父 div 小于容器 div 所以溢出:隐藏;隐藏一半的容器内容。
是否可以只用 css 做到这一点?
这是代码:
<div id="container">
<div class="content">
<div class="wrapper">
Content here
</div>
</div>
#container {
float: left;
height: 400px;
width: 400px;
background-color: red;
}
.content {
float: left;
height: inherit;
width: 90%;
overflow: hidden;
position: relative;
background-color: black;
}
.wrapper {
width: 90%;
height: 900px;
position: relative;
z-index: 99;
background-color: blue;
}
您可能使用 overflow
属性 来清除浮动,对吗?
然后将overflow: hidden
改为overflow: auto
。
设置内容div最小高度:400px; (替换高度)所以它永远不会小于容器,但可以根据需要变大。