html - 将div的高度设置为父div的底部
问题描述
我在父 div 中有 2 个 div:
.core {
height: 200px;
/* 200% px is just for showcase, in my app I am using % of another div... */
background-color: yellow;
}
.boxName {
display: block;
position: relative;
}
.boxName span {
background-color: black;
color: white;
}
.basicInfo {
position: relative;
/*margin-bottom and bottom don't change anything*/
/*height sets height but including height of the title
height: 100%;
margin-bottom: 0%;*/
bottom: 0%;
width: 30%;
background-color: green;
}
<div class="core">
<div class="boxName"><span>Title</span></div>
<div class="basicInfo">
How to set height of this div to the bottom of core div?
</div>
</div>
现在我想确保 basicInfo div 在核心 div 结束的地方结束(底部对齐)。
我从其他帖子中尝试了很多东西,例如 display: flex, bottom: 0%, margin-bottom: 0% 等。
我很高兴收到你的来信,我做错了什么。在这种情况下,我宁愿不使用 position: absolute 。
小提琴。
谢谢,马辛
解决方案
只需使用弹性:
.core {
height: 200px;
background-color: yellow;
/* add these */
display: flex;
flex-direction: column;
}
.boxName {
display: block;
position: relative;
}
.boxName span {
background-color: black;
color: white;
}
.basicInfo {
position: relative;
width: 30%;
background-color: green;
/* add this (makes the second div grow to fill the rest of the column) */
flex-grow: 1;
}
<div class="core">
<div class="boxName"><span>Title</span></div>
<div class="basicInfo">
How to set height of this div to the bottom of core div?
</div>
</div>
推荐阅读
- java - 如何在自定义验证注释上插入 ConstraintValidator 消息
- python - 将二维列表中的每个项目乘以 python 中的标量
- javascript - 将 JSX 存储在服务器上,通过 API 检索它,并使用 onClick 函数渲染它
- postscript - 后记:需要帮助理解遗留代码
- ios - 为什么桌面视图与 iPhone X~iPhone XS Max 的大小不同?
- three.js - 三.js OBJLoader 回调未执行
- ssl - TCP/IP 套接字无法与 TLSv1_2_client_method() 建立安全连接
- php - 根据选择的另一个选择选项更改选择选项
- python - talib.LINEARREG 是如何工作的?
- sql - 从存在的地方删除——抛出错误