CSS grid-column-end

The CSS grid-column-end property is used to span a grid item for specified number of columns. Or to define the ending column position of a grid item in grid layout. For example:

HTML with CSS Code
<!DOCTYPE html>
<html>
<head>
   <style>
      div.container {display: grid; gap: 4px; grid-template-columns: auto auto auto;}
      div.container > div {border: 2px solid chocolate; padding: 10px; text-align: center;}
      #myIdOne {grid-column-end: span 3;}
   </style>
</head>
<body>

   <div class="container">
      <div id="myIdOne">A</div>
      <div>B</div>
      <div>C</div>
      <div>D</div>
   </div>
   
</body>
</html>
Output
A
B
C
D

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-column-end Syntax

The syntax of grid-column-end property in CSS, is:

grid-column-end: auto|span n|columnLineNumber;

CSS grid-column-end: columnLineNumber Example

The columnLineNumber refers to a number, used when we need to define the position or column line number, where we need to place the particular grid item. For example:

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

   <div class="container">
      <div id="a">A</div>
      <div id="b">B</div>
      <div id="c">C</div>
      <div id="d">D</div>
      <div id="e">E</div>
      <div id="f">F</div>
      <div id="g">G</div>
      <div id="h">H</div>
      <div id="i">I</div>
      <div id="j">J</div>
   </div>
   
</body>
</html>
Output
A
B
C
D
E
F
G
H
I
J

CSS Online Test


« Previous Tutorial Next Tutorial »


Liked this post? Share it!