html - 嵌套的 CSS 网格行为异常
问题描述
如果您查看 Firefox 中的嵌套网格并查看网格显示,您将看到四个单独的嵌套网格,每个网格有 1 行和 12 列。但是,如果您查看 CSS 文件,您只能分配元素“main-services-text”、“main-banner-text”等,将其视为单个 4 行网格。
所以我的问题是,这是它应该工作的方式还是它是一个错误。我也应该使用它吗?
.main-grid {
display: grid;
grid-template-columns: repeat(12, 1fr);
grid-template-rows: 100px 100px 100px 100px;
}
/* Step 1a assign the main elements "" to the MAIN Grid*/
.main-banner {
grid-column: 1 /13;
grid-row: 1 / 2;
background-color: cornflowerblue;
}
.main-services {
grid-column: 1 /13;
grid-row: 2 / 3;
background-color: lightcyan;
}
.main-why-us {
grid-column: 1 /13;
grid-row: 3 / 4;
background-color: orange;
}
.main-who-are-we {
grid-column: 1 /13;
grid-row: 4 / 5;
background-color: chocolate;
}
/* Step 2: Set up individual nested GRIDS*/
main section {
display: grid;
color: olive;
grid-template-columns: repeat(12, 1fr);
grid-template-rows: 100px;
}
/* Step 2 assign elements to the nested grids */
.main-banner-text {
grid-column: 3 / 5;
grid-row: 1 / 2;
}
.main-services-text {
grid-column: 6 / 9;
grid-row: 2 / 3;
}
.main-why-us-text {
grid-column: 10 / 13;
grid-row: 3 / 4;
}
.main-who-are-we-text {
grid-column: 9 / 10;
grid-row: 4 / 5;
}
<main class="main-grid">
<section class="main-banner">Banner</section>
<p class="main-banner-text">Main banner text</p>
<section class="main-services">Services</section>
<p class="main-services-text">Main services text</p>
<section class="main-why-us">Why Us</section>
<p class="main-why-us-text">Main Why us text</p>
<section class="main-who-are-we">Who are we</section>
<p class="main-who-are-we-text">Main who are we text</p>
</main>
解决方案
推荐阅读
- java - 如何将一个 Eclipse 项目的方法/变量调用到另一个 Eclipse 项目?
- apache-camel - Apache Camel文件端点:Camel测试调用直接组件路由将文件从文件夹A复制到文件夹B
- python - .split() 与 json 文件返回 keyerror
- typescript - 使用 TypeScript 的 CreateJS
- r - 使用 dplyr 在数据框中的每个组的开头添加一行
- javascript - 为 React 钩子更新 Javascript 对象中的属性的最有效方法
- excel - 如何计算 Excel 中两个 ISO 8601 日期时间之间的秒数?
- javascript - 保存和恢复 Chrome 扩展中多个复选框的检查状态
- c# - 将 DomainDbContext 与 IdentityDbContext 解耦
- python-3.x - Gurobi:在目标函数中添加对数项和指数项?