Html 如何为容器div指定内部div的高度
我必须潜水 类为d且背景色为红色的容器 内部为class=d2,背景色为灰色 如下图所示 我想让div d达到div d2的高度,但我不知道怎么做 这是密码Html 如何为容器div指定内部div的高度,html,css,Html,Css,我必须潜水 类为d且背景色为红色的容器 内部为class=d2,背景色为灰色 如下图所示 我想让div d达到div d2的高度,但我不知道怎么做 这是密码 .d { width:100%; height:100px; background-color:red; } .d2 { width:80%; height:auto; float:left; background-color:Gray; } 如果我将div d的高
.d
{
width:100%;
height:100px;
background-color:red;
}
.d2
{
width:80%;
height:auto;
float:left;
background-color:Gray;
}
如果我将div d的高度设置为“auto”,红色将“消失”如果
.d
具有指定的高度(在您的情况下,它是--100px),那么您可以设置
.d2 {
height: 100%;
}
因为您已经设置了d的高度:
.d
{
width:100%;
height:100px;
background-color:red;
}
将d2的高度设置为100px或100%:
.d2
{
width:80%;
height:100px;
float:left;
background-color:Gray;
}
你需要另一个div,样式很清晰:都是这样,那么d的高度可以设置为auto
<style>
.d
{
width:100%;
height:auto;
background-color:red;
}
.d2
{
width:80%;
height:auto;
float:left;
background-color:Gray;
}
</style>
<div class="d">
<div class="d2">
type something here<br />
<br />
<br />
<br />
<br />
something again the parent div's height will depend by this div
</div>
<div style="clear:both;">
</div>
D
{
宽度:100%;
高度:自动;
背景色:红色;
}
.d2
{
宽度:80%;
高度:自动;
浮动:左;
背景颜色:灰色;
}
在此处键入内容
同样,父div的高度将取决于此div
在我看来,你的d2
高度比你的d
容器大。如果d2
较小,我想您不希望您的容器具有与d2
相同的高度,但如果它较大,您的d
容器仍应足够大
如果是这种情况,将d
中的高度更改为最小高度:100px代码>