我的以下代码有问题

header {
Position : absolute;
Display: inline-block;
Width: 15%;
Height: 100%;
Left: 0;
Top: 0;
}

.headerchild {
Display: block;
Width: 100%;
Padding-bottom: 20%;
Float: left;
}

Headerchildchildeader {
Position : absolute;
Display: inline-block;
Width: 80%;
Height: 100%;
Left: 20%;
}


问题是我的headerchildchild从其父parent标头而不是从其parent headerchild计算高度

最佳答案

我想我得到了你想要的。

您要做的就是在headerchild子类中添加position属性,即

 .headerchild {
   position: relative; //newly added property
   Display: block;
   Width: 100%;
   Padding-bottom: 20%;
   Float: left;
}

关于html - div元素不会从其 float 父级继承高度的百分比,也不会从其父级父级继承高度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41333138/

10-11 13:20