codescracker
css

CSS grid-row



The grid-row property is used to define the row start and end position of a grid item in grid layout, to place the item at desired position with specified number of rows (spaces/heights). For example:

HTML with CSS Code
<!DOCTYPE html>
<html>
<head>
   <style>
      .container {display: grid; gap: 4px; background-color: peru; color: whitesmoke;
         grid-template-columns: auto auto auto;}
      .container > div {background-color: maroon; padding: 10px; text-align: center;}
      #a {grid-row: 1 / 4;}
      #b {grid-row: 1 / 3;}
   </style>
</head>
<body>

   <div class="container">
      <div id="a">1</div>
      <div id="b">2</div>
      <div>3</div>
      <div>4</div>
      <div>5</div>
      <div>6</div>
   </div>
   
</body>
</html>
Output
1
2
3
4
5
6

From above example, the following CSS code:

#a {grid-row: 1 / 4;}
#b {grid-row: 1 / 3;}

can also be written as:

#a {grid-row: 1 / span 3;}
#b {grid-row: 1 / span 2;}

Note - The grid as the value of display property, is used to make an element as a block level grid container.

Note - The gap property is used to define the gap between rows and columns in grid layout.

Note - The grid-template-columns is used to define the number of columns to create in grid layout.

CSS grid-row Syntax

The syntax of grid-row property in CSS, is:

grid-row: grid-row-start / grid-row-end;

The grid-row property is used as shorthand of following two CSS properties:

CSS Online Test


« Previous Tutorial Next Tutorial »



© Copyright 2021. All Rights Reserved.

CodesCracker