html - 如何使 CSS 网格对其中的变化元素无响应?
问题描述
我有一个像这样的基本网格。我怎样才能让它对里面的变化元素没有反应?示例:如果我将按钮之类的元素放入其中并且文本发生更改(例如从“未准备好”变为“准备好”),则整个容器的大小应该保持不变。但我真的找不到任何方法来实现这一目标。还是我使用了错误的技术?
<div class="container">
<div class="header"></div>
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
</div>
<style>
.container {
display: grid;
grid-template-columns: 1fr 0.7fr 1.3fr;
grid-template-rows: 0.2fr 0.6fr 1.6fr;
gap: 0px 0px;
grid-template-areas:
"header header header"
"one one two"
"one one three";
}
.header { grid-area: header; }
.one { grid-area: one; }
.two { grid-area: two; }
.three { grid-area: three; }
</style>
解决方案
使用百分比而不是fr
列上的灵活长度,例如grid-template-columns: 30% 30% 40%;
试试下面的代码片段
.container {
display: grid;
grid-template-columns: 30% 30% 40%;
grid-template-rows: 0.2fr 0.6fr 1.6fr;
gap: 0px 0px;
height:100vh;
border:1px solid black;
grid-template-areas:
"header header header"
"one one two"
"one one three";
}
.header { grid-area: header; border:1px solid blue; }
.one { grid-area: one; border:1px solid blue;}
.two { grid-area: two; border:1px solid blue;}
.three { grid-area: three; border:1px solid blue;}
<div class="container">
<div class="header"></div>
<div class="one"></div>
<div class="two"></div>
<div class="three"><button>way waaay more than ready</button></div>
</div>
推荐阅读
- node.js - 并行实现应用登录和实时通信
- docker - Jenkins Pipeline 无法使用 docker-compose 运行,因为它无法连接到 docker 守护进程
- python - 在 Raspberry Pi 中安装 numpy 时,SSH 中止了连接
- c++ - 关于指针引用的说明
- c# - 如何使用户能够使用 xamarin 媒体插件从图库中选择图像并重命名图像
- unix - 如何将内容grep到新文件?
- sql - 从 SQL 数据库公开数据的最佳选择
- asp.net - 当 URL 为 /AUX 且 RelaxUrlToFileSystemMapping 为 false 时如何显示自定义错误页面
- html - 如何使两个居中没有它们重叠?
- ios - 如何在 iOS SDK 中检查用户的设备