css - Css Grid 布局 1fr 超过父高度
问题描述
我做了一个演示来演示我的问题
<style>
.main {
display: grid;
grid-template-rows: 1fr auto;
background-color: red;
width: 300px;
height: 120px;
}
.top {
height: 50px;
background-color: blue;
}
.bottom {
display: grid;
grid-template-columns: minmax(100px, 30%) auto;
column-gap: 10px;
margin: 10px;
}
.left {
background-color: green;
max-height: 100%;
overflow-y: scroll;
}
.right {
background-color: yellow;
}
</style>
<div class="main">
<div class="top">My content</div>
<div class="bottom">
<div class="left">Left hkjs ajsgf dh a sk si sk dils k lkao one sp shek siej</div>
<div class="right">Right</div>
</div>
</div>
绿色 div 超过其父 div 的高度。我希望绿色 div 位于红色 div 内,并且只要内容超过父级的高度,就会有一个滚动条。
我不知道我解释我的问题有多清楚,但请帮助我。
解决方案
添加min-height:0
到父元素。
<style>
.main {
display: grid;
grid-template-rows: 1fr auto;
background-color: red;
width: 300px;
height: 120px;
}
.top {
height: 50px;
background-color: blue;
}
.bottom {
display: grid;
grid-template-columns: minmax(100px, 30%) auto;
column-gap: 10px;
margin: 10px;
min-height:0;
}
.left {
background-color: green;
max-height: 100%;
overflow-y: scroll;
}
.right {
background-color: yellow;
}
</style>
<div class="main">
<div class="top">My content</div>
<div class="bottom">
<div class="left">Left hkjs ajsgf dh a sk si sk dils k lkao one sp shek siej</div>
<div class="right">Right</div>
</div>
</div>
推荐阅读
- sql - 如何使用连接表中的值过滤一个表中的行
- matlab - 查找 Simulink 模型 Matlab 的所有输入
- python - 如何确保 RNG 熵池对于使用 passlib 生成密码是“安全且完整的”?
- python - 连接列中的单词
- birt - 引用 Birt 中的报告字段
- javascript - 仅使用 javascript 向 id 添加悬停工具提示
- python - PROJ pyproj 点 EPSG 4326 (WSG 84) 到 (EPSG 28992) 的转换
- javascript - sessionStorge 上的数据集在同一选项卡的其他页面上不可用
- r - 有没有办法使用 mutate 循环列名?
- sql - “排序依据”子句中的语法错误 - Microsoft Access 中的 SQL