Categories
CSS Web development

CSS grid-row-start Property

CSS grid-row-start Property

The CSS grid-row-start property specifies on which row-line the item will start.

Syntax:

grid-row-start: auto|row-line;

auto (default) – the item will be placed by following the flow.

row-line – defines on which row to start the display of the item.

Example1 (auto):

<!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: 25px 0;
  font-size: 30px;
}

.item1 {
  grid-row-start: auto;
}
</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 class="item8">8</div>
</div>

</body>
</html>

Output:

1
2
3
4
5
6
7
8

Example2 (row-line):

Make “item-1” start on row 2:

<!DOCTYPE html>
<html>
<head>
<style>
.grid-container1 {
  display: grid;
  grid-template-columns: auto auto auto auto;
  grid-gap: 10px;
  background-color: #e9c46a;
  padding: 10px;
}

.grid-container1 > div {
  background-color: #f4a261;
  text-align: center;
  padding: 25px 0;
  font-size: 30px;
}

.item-1 {
  grid-row-start: 2;
}
</style>
</head>
<body>

<div class="grid-container1">
  <div class="item-1">1</div>
  <div class="item-2">2</div>
  <div class="item-3">3</div>  
  <div class="item-4">4</div>
  <div class="item-5">5</div>
  <div class="item-6">6</div>
  <div class="item-7">7</div>
  <div class="item-8">8</div>
</div>

</body>
</html>

Output:

1
2
3
4
5
6
7
8

Enjoy coding!