如何计算动态元素的高度?
How can I calculate the height of dynamic elements?
下面是我的代码:
.parent{
position: fixed;
border: 1px solid;
height: 40%;
width: 300px;
max-height: 200px;
}
.first_child{
border: 1px solid blue;
padding: 10px;
height: 20px;
text-align: center;
}
.second_child{
border: 1px solid red;
height: 100%;
overflow-y: scroll;
}
<div class="parent">
<div class="first_child">title</div>
<div class="second_child">
one<br>two<br>three<br>four<br>five<br>six<br>seven<br>eight<br>night<br>ten<br>
</div>
</div>
如你所见,.second_child
脱离了parent
。我想把它保存在.parent
元素中。我该怎么做呢?
换句话说,我想实现这样的东西:
.second_child{
height: 100% - 40px;
/* 40px: 20px of .first_child's height, 10+10px of .first_child's padding */
...
}
注意:我不想使用calc()
或box-sizing: border-box;
..因为像IE7这样的旧浏览器不支持它们。所以我在寻找第三种方法
这样的东西会起作用吗?
.parent{
position: relative;
border: 1px solid;
height: 100%;
width: 300px;
max-height: 200px;
min-height: 100px;
}
.first_child{
border: 1px solid blue;
padding: 10px;
height: 20px;
text-align: center;
}
.second_child{
border: 1px solid red;
overflow-y: scroll;
position: absolute;
top: 40px;
right: 0;
bottom: 0;
left: 0;
}
<div class="parent">
<div class="first_child">title</div>
<div class="second_child">
one<br>two<br>three<br>four<br>five<br>six<br>seven<br>eight<br>night<br>ten<br>
</div>
</div>
相关文章:
- 查找元素高度,包括边距
- 根据元素高度和宽度的百分比变化增加或减少字体大小
- 更改第二次推送时不起作用的元素高度
- 指示中的角度手表元素高度
- 在 HTML/CSS 中更改元素高度与宽度的比较
- 获取元素高度的正确方法(使用所有浏览器?)
- 访问NativeScript中的元素高度
- 如何“;“修复”;显示滚动条时的容器元素高度
- 当元素高度不够时,如何强制滚动
- CSS webkit溢出隐藏和HTML元素高度
- 如果元素高度大于 x 添加类“纵向”,则添加类“横向”
- 如何获取离子对话框中动态加载的元素的元素高度
- AngularJS 指令中的元素高度
- 铬:设置元素高度的脚本是什么
- 哇.js偏移等于元素高度
- 如何获得隐藏元素高度
- jQuery - 如果其他元素可见,则更改元素高度
- 根据元素高度拆分段落的最有效方法
- 检测元素高度变化,如果太小则隐藏
- 根据 jQuery 中多个实例上的另一个元素高度设置高度