html - Repeat two rows pattern in CSS Grid
问题描述
I want to mimic this pattern (over and over):
So I wrote grid-template-columns: 65% 35%
for the first row. Yet, I want to do grid-template-columns: 65% 35%
for a second row (and the fourth, and the sixth and so on), but I'm not sure how can I do that while maintaining 65%
and 35%
.
#parent {
display: grid;
grid-template-columns: 60% 40%;
grid-gap: 24px;
}
.child {
height: 150px;
background-color: #DDD;
}
<div id="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div
解决方案
You can achieve this by creating a three-column grid with grid-template-columns: repeat(3, 33.333%);
and adding an additional class for the children that will stretch the element into two columns grid-column: span 2;
Result:
https://codepen.io/hisbvdis/pen/vYBaZQb
#parent {
display: grid;
grid-template-columns: repeat(3, 33.333%);
grid-gap: 24px;
}
.child {
height: 150px;
background-color: #DDD;
}
.wide {
grid-column: span 2;
}
<div id="parent">
<div class="child wide"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child wide"></div>
<div class="child wide"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child wide"></div>
</div
推荐阅读
- symfony - 如何使用 symfony 序列化程序更改 XML 中的节点名称?
- python - 如何快速将纬度和经度放在一列?
- image - 打包程序映像:创建映像后复制的文件不存在
- spring - 在春季启动批处理中将排序规则,字符集从 latin1_swedish_ci 更改为 utf8
- .net - 在 .NET API 中添加对 PresentationCore.dll 和 PresentationFramework.dll 的引用
- android - Android 平板电脑三星 Galaxy A SM T515 测试在 Play 商店中不兼容
- python - 为什么我的按钮在我的 pyqt5 GUI 中不起作用?
- javascript - 将字典(对象)从html元素传递给js点击事件监听器
- css - 修复了 Firefox 中的模糊背景边缘有白光
- html - 在 td 单元格的 div 中设置 margin-top