css - 防止 CSS 网格子扩展父级
问题描述
我有以下CSS
html,body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
.one {
width: 100%;
height: 100%;
display: grid;
grid-template-columns: minmax(0, 1fr) 20%;
}
.two {
background: red;
}
.three {
background: blue;
display: grid;
grid-template-rows: 64px minmax(0, 1fr) 58px;
}
.five {
background: orange;
height: 800px;
overflow-y: auto;
}
.four {
background: green;
}
.size {
background: blue;
}
<div class="one">
<div class="two">
</div>
<div class="three">
<div class="four"></div>
<div class="five"></div>
<div class="six"></div>
</div>
</div>
现在,正如您从https://codepen.io/dubcanada/pen/ZEbYBex看到的那样,如果五个比三个高 - 122 像素(64 + 58 像素),它会扩展三个以适应的高度。我希望它添加一个滚动条而不是扩大高度。
我已经尝试了min-height: 0;, max-height: 0; min-width: 0; max-width: 0;
技巧,我能想到的一切我不知道如何解决这个问题。
有任何想法吗?
解决方案
不知道你想达到什么...
这是我最好的猜测:
html,body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
.one {
width: 100%;
height: 100%;
display: grid;
grid-template-columns: minmax(0, 1fr) 20%;
grid-template-rows: minmax(0, 1fr);
}
.two {
background: red;
}
.three {
background: blue;
display: grid;
grid-template-rows: 64px minmax(0, 1fr) 58px;
max-height: 100%;
}
.five {
background: orange;
height: 500px;
overflow-y: auto;
max-height: 100%;
}
.four {
background: green;
}
.size {
background: blue;
}
<div class="one">
<div class="two">2
</div>
<div class="three">
<div class="four">4</div>
<div class="five">5</div>
<div class="six">6</div>
</div>
</div>
推荐阅读
- php - 雄辩的 stdClass 对象返回数组?
- javascript - Javascript:格式化日期
- c# - Microsoft.Extensions.Logging.Console 在控制台应用程序中不起作用
- ios - iOS中的重复本地通知 - 目标c
- javascript - Enable CORS in httpd.conf
- ios - WKWebView 媒体控件标题显示Url
- jquery - jQuery 错误 > inject.preload(新手)
- php - 为什么点击搜索按钮后出现分页错误?
- mongodb - 环回 MongoDB - 部署
- intellij-idea - Gosu 中有效的@SuppressWarnings 警告名称列表是什么?