According to MDN Web Docs, the grid CSS property is a shorthand property that sets all of the explicit and implicit grid properties in a single declaration. I wonder how we can use it instead of grid-column & grid-row in the following sample code so it can be further shortened:
.grid-container {
display: grid;
gap: 10px;
background-color: #2196F3;
padding: 10px;
}
.grid-container div {
background-color: rgba(255, 255, 255, 0.8);
text-align: center;
padding: 20px 0;
font-size: 30px;
}
.item3 {
grid-column: 2;
grid-row: 1 / 3;
}
<div >
<div >1</div>
<div >2</div>
<div >3</div>
</div>
CodePudding user response:
You are looking for grid-area. grid is for the container
.grid-container {
display: grid;
gap: 10px;
background-color: #2196F3;
padding: 10px;
}
.grid-container div {
background-color: rgba(255, 255, 255, 0.8);
text-align: center;
padding: 20px 0;
font-size: 30px;
}
.item3 {
/*grid-column: 2;
grid-row: 1 / 3;*/
grid-area: 1 / 2 / 3 /auto;
/* row-start / column-start / row-end / column-end */
}
<div >
<div >1</div>
<div >2</div>
<div >3</div>
</div>
CodePudding user response:
No, that is not the purpose of it. The shorthand replaces grid-template-columns and grid-template-rows on the grid container.
