html - div 元素不会从其 float 父元素继承高度(以 % 为单位),而是从其父元素继承高度

标签 html css

下面的代码有问题

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 从其父级 header 而不是从其父级 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/

相关文章:

php - 他们说 HTML 中的 javascript 代码被认为是不好的做法,如何解决这个问题?

javascript - 至少 1000000 div 的大网格

html - 如何使div高度为他父级的100%?

jquery - 从 div 触发花式框?

PHP Bootstrap 3 文本关闭区域?

html - 如何处理 Bootstrap 图像网格中的肖像图像

javascript - Zurb Foundation 5.3 - Off Canvas 不工作 "TypeError: this[method] is undefined"

php - 如何在 css 中使用 php 制作内容属性

javascript - 表单字段中的 html 标记不起作用

css - IE8 和其他所有内容之间的 CSS 旋转的一致来源?