如何更改每个网格行之间的垂直间隙?
我尝试过使用grid-gap
,但这只会改变水平间隙而不是垂直间隙。任何帮助,将不胜感激。
.wrapper {
background-color: #1c1c1c;
border: solid black 1px;
margin-left: auto;
margin-right: auto;
width: 1000px;
display: grid;
grid-gap: 10px;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
grid-template-rows: 1fr;
grid-template-areas: 'header header header header header' 'menu content content content content' 'menu content content content content' 'footer footer footer footer footer';
}
.header {
grid-area: header;
border: solid white 1px;
background-color: #3a3a3a;
margin: 10px;
}
.menu {
grid-area: menu;
border: solid white 1px;
background-color: #3a3a3a;
margin: 10px;
}
.content {
grid-area: content;
border: solid white 1px;
background-color: #3a3a3a;
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr 1fr 1fr;
grid-gap: 5px;
overflow-y: scroll;
}
.footer {
grid-area: footer;
border: solid white 1px;
background-color: #3a3a3a;
margin: 10px;
}
.menu-item {
list-style: none;
text-align: center;
margin: 10px;
padding: 10px;
border: solid white 1px;
background-color: #1e1e1e;
color: white;
font-family: Arial;
font-size: 20px;
font-weight: bold;
text-transform: uppercase;
}
.madeby {
list-style: none;
text-align: center;
margin: 10px;
padding: 10px;
background-color: #1e1e1e;
color: white;
font-family: Arial;
font-size: 20px;
font-weight: bold;
text-transform: uppercase;
}
.content {
list-style: none;
grid-area: content;
margin: 10px;
padding: 10px;
background-color: #3a3a3a;
}
.top {
list-style: none;
text-align: center;
margin: 10px;
padding: 10px;
background-color: #1e1e1e;
color: white;
font-family: Arial;
font-size: 20px;
font-weight: bold;
text-transform: uppercase;
}
.cell {
border: solid white 1px;
color: white;
font-family: Arial;
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
text-align: center;
height: 20px;
line-height: 20px;
background-color: #1e1e1e;
}
<div class="wrapper">
<div class="header">
<div class="top">header</div>
</div>
<div class="menu">
<li class="menu-item">menu</li>
<li class="menu-item">menu</li>
<li class="menu-item">menu</li>
<li class="menu-item">menu</li>
<li class="menu-item">menu</li>
</div>
<div class="content">
<input class="cell" type="text" value="dato">
<input class="cell" type="text" value="nøkkelvaner">
<input class="cell" type="text" value="oppsumering">
<input class="cell" type="text" value="oppgaver">
<input class="cell" type="text" value="andre">
<input class="cell" type="text" value="dato">
</div>
<div class="footer">
<div class="madeby">footer</div>
</div>
</div>
你可以使用grid-gap
属性来解决这个问题,它是grid-row-gap
和grid-column-gap
的速记属性。第一个值是水平间隙(行间隙),第二个值是垂直间隙(列间隙)
grid-gap: 10px 20px;
您还可以使用以下属性设置网格之间的差距:
grid-row-gap: 10px;
grid-column-gap: 20px;
根据Mozilla文档:
此属性指定为<'row-gap'>的值,后面可选> <column-gap'>的值。如果省略<'column-gap'>,则将其设置为与<'row-gap'>相同的>值。
因此,在您的代码中,您只为行设置了网格间隙,您还应该为列添加第二个值(垂直)
grid-gap
属性定义网格布局中行和列之间间隙的大小,并且是以下属性的简写属性:
你也可以使用grid-row-gap
或grid-column-gap