【发布时间】:2017-03-12 06:19:25
【问题描述】:
我正在尝试将 CSS 网格布局用作 described here。
我的问题是,在成功编写了两行网格布局后,我无法正确获取第三行的布局。第三行不知何故盖住了第二行。
下面是代码的基本结构,可以让您了解我正在尝试做什么。我包含所有代码的存储库是here。
查看已发布的页面时,很明显前两行布局正确,但不幸的是第三行不符合网格布局(并覆盖在第二行上)。
有人知道我如何正确布置第三行吗?
我的 HTML 结构:
<body>
<header class="hero">
</header>
<main role="main">
<section class="tech">
</section>
<section class="afford">
<h1>This heading should be in the next section</h1>
</section>
</main>
</body>
CSS 的结构:
body {
font-family: 'Lato', sans-serif;
width: 100%;
margin: 0 auto;
display: grid;
margin: 0 auto;
grid-template-columns: 10% auto auto 10%;
grid-template-rows: auto auto auto auto auto;
grid-template-areas: "hero hero hero hero"
"tech tech tech tech"
"afford afford afford afford"
". . . ."
". . . .";
box-sizing: border-box;
height: 100vh;
}
.hero {
grid-area: hero;
background-image: url('../images/people-working.jpg');
width: 100%;
height: 928px;
background-size: cover;
background-position: center;
}
.tech {
grid-area: tech;
width: 100%;
height: 712px;
position: absolute;
text-align: center;
}
.afford {
grid-area: afford;
width: 100%;
height: 832px;
position: absolute;
text-align: center;
}
【问题讨论】: