Categories
CSS Web development

CSS grid-row-end Property

CSS grid-row-end Property

The CSS grid-row-end property specifies how many rows an item will span, or on which row-line the item will end.

Syntax:

grid-row-end: auto|integer|span n;

auto (default) – the item will span one row.

integer – defines the row on which the item ends.

span n – defines the number of rows the item will span.

Example1:

Item1 will span 2 rows:

<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
  display: grid;
  grid-template-columns: 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-row-end: 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 class="item8">8</div>
</div>

</body>
</html>

Output:

1
2
3
4
5
6
7
8

Example2:

Item-1 will end on row-line 4:

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

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

.item-1 {
  grid-row-end: 4;
}
</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!