是否可以解决某些网格模板区域,还是必须创建子网格或子Flexbox才能实现进一步定位?
例如,在以下代码示例中,我想将项目放置在三个标头部分的最后一个中。最有效的方法是什么?
.grid-main {
display: grid;
height: 98vh;
width: 98vw;
overflow: hidden;
overflow: -moz-hidden-unscrollable;
grid-template-columns: 175px 1fr 1fr;
grid-template-rows: 0.1fr 1fr 0.075fr;
grid-template-areas:
"header header header"
"nav main main"
"footer footer footer";
animation: fadeIn 2s;
transition: 1s all ease-in-out;
}
答案 0 :(得分:1)
是的,您可以定义grid-area
,也可以定义grid-column
或行。
示例
body {
display: grid;
height: 98vh;
width: 98vw;
overflow: hidden;
overflow: -moz-hidden-unscrollable;
grid-template-columns: 175px 1fr 1fr;
grid-template-rows: 0.1fr 1fr 0.075fr;
grid-template-areas: "header header header" "nav main main" "footer footer footer";
animation: fadeIn 2s;
transition: 1s all ease-in-out;
}
header {
grid-area: header;
grid-column: span 2;
background: cyan
}
p {
grid-area: header;
background: tomato;
grid-column: span 1;
margin: 0;
}
nav {
grid-area: nav;
background: lightgreen
}
footer {
grid-area: footer;
background: brown
}
main {
grid-area: main;
background: gray;
}
<header>header</header>
<p>something else</p>
<nav>nav</nav>
<main>main</main>
<footer>footer</footer>