Categories
CSS Web development

CSS gap Property

CSS gap Property

The CSS gap property specifies the size of the space between the rows and columns. It is a shorthand for the following properties:

Syntax:

gap: row-gap column-gap;

row-gap – sets the size of the space between the rows in a grid layout.

column-gap – sets the size of the space between the columns in a grid layout.

gap: 20px 20px;

is a shorthand for:

row-gap: 20px;
column-gap: 25px;

Example:

<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
  display: grid;
  grid-template-columns: auto auto auto;
  gap: 20px 25px;
}
.grid-container > div {
  border: 1px solid #333;
  background-color: #e9c46a;
}
</style>
</head>
<body>

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

</body>
</html>

Output:

1
2
3
4
5
6
7
8
9

Enjoy coding!

Read also:

CSS grid-auto-flow Property

CSS Grid Layout

Categories
Web development

CSS column-gap Property

CSS column-gap Property

The CSS column-gap property defines the space between the columns.

Syntax:

column-gap: length|normal;

length – a defined length that will set the space between the columns.

normal (default) – defines a normal space between the columns.

Example:

<!DOCTYPE html>
<html>
<head>
<style> 
.text {
  column-count: 3;
  column-gap: 30px;
}
</style>
</head>
<body>

<div class="text">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. 
</div>

</body>
</html>

Output:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.

Enjoy coding!

Read also:

CSS Columns

CSS row-gap Property