html - 将 div 的高度设置为另一个 div 高度
问题描述
我有一个这样的页面:
<div id="parent">
<div id="childA">
List of some contents
</div>
<div id="childB">
The main content
</div>
</div>
#childA{
display: inline-block;
}
#childB{
display: inline-block;
}
我想将父div的高度设置为childB的高度,而不是childA的高度。如果 childA 作为滚动条,以防它变得比 childB 大。 编辑:我刚刚意识到我可以从不同的角度解决问题。我希望它可以帮助你理解我想要什么。我需要根据它旁边的div(childB)的高度来设置一个div(childA)的高度。
#childB{
overflow-y: scroll;
}
两个孩子的身高各不相同,但我希望我父母的身高等于 childB 的身高。我尝试使用表:
#parent{
display: table;
}
#childB{
display: table-row;
}
但是当childA大于childB时,childA会不断增加父母的身高
PS 我知道我可以使用 JavaScript,但我不想使用它。
解决方案
我希望下面的示例能让您了解在 childA 上设置一些 height 和 overflow-y 有何帮助。
#parent {
display: flex;
border: 1px solid black;
}
#childA {
overflow-y: scroll;
height: 60px;
}
#childB {
}
<div id="parent">
<div id="childA">
List of some contents
List of some contents
List of some contents
List of some contents
List of some contents
</div>
<div id="childB">
The main content
The main content
The main contentThe main contentThe main content
The main content
The main content
The main content
The main content
</div>
</div>
推荐阅读
- mysql - 删除 wordpress 帖子中的脚本
- asp.net - asp.net mvc [授权()]
- javascript - 快速请求和响应的顺序
- java - 访问多部分表单属性值 - Vert.x / Quarkus
- java - 网址更改链接
- python - 如何检查我是否使用 conda 或 pip 安装了 Python、pandas 和 Jupyter?我应该用 conda 重新安装它吗?
- php - 带有自定义 SQS 数据的 Laravel 队列
- javascript - 尝试在 Google Apps 脚本中拼凑数据时,如何将 getRange() 函数与 forLoop 结合使用?
- entity-framework-core - EF Core 3.1 迁移没有看到变化
- line - 如何在 Python 上使用反斜杠?