
The CSS grid-column property defines a grid item’s size and location in a grid layout, and is a shorthand property for the following properties:
Syntax:
grid-column: grid-column-start / grid-column-end;
grid-column-start – defines on which column to start displaying the item.
grid-column-end – defines on which column-line to stop displaying the item, or how many columns to span.
grid-column: 1 / span 2;
is a shorthand for:
grid-column-start: 1;
grid-column-end: span 2;
Example:
Item1 will start on column 1, and span 2 columns:
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
grid-template-columns: auto auto auto auto;
grid-gap: 10px;
background-color: #e9c46a;
padding: 10px;
}
.grid-container > div {
background-color: #f4a261;
text-align: center;
padding: 20px 0;
font-size: 30px;
}
.item1 {
grid-column: 1 / span 2;
}
</style>
</head>
<body>
<div class="grid-container">
<div class="item1">1</div>
<div class="item2">2</div>
<div class="item3">3</div>
<div class="item4">4</div>
<div class="item5">5</div>
<div class="item6">6</div>
<div class="item7">7</div>
</div>
</body>
</html>
Output:
1
2
3
4
5
6
7
Enjoy coding!
Read also: