Grid Container

CSS Tutorial


Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2299

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2303

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2309

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2313

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2317

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2321

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2335

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2299

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2303

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2309

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2313

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2317

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2321

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2335

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2299

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2303

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2309

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2313

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2317

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2321

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2335

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2299

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2303

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2309

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2313

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2317

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2321

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2335

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2299

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2303

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2309

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2313

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2317

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2321

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2335

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2299

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2303

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2309

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2313

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2317

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2321

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2335

CSS Advanced


Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2299

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2303

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2309

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2313

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2317

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2321

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2335

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2299

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2303

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2309

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2313

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2317

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2321

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2335

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2299

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2303

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2309

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2313

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2317

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2321

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2335

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2299

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2303

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2309

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2313

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2317

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2321

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2335

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2299

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2303

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2309

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2313

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2317

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2321

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2335

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2299

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2303

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2309

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2313

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2317

Notice: Trying to get property 'post_status' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2321

Notice: Trying to get property 'ID' of non-object in /home/u212091429/domains/allhostingdeals.com/public_html/wp-admin/includes/template.php on line 2335

CSS Responsive

CSS Grid

CSS Grid Container

Grid Container

To make an HTML element behave like a grid container, the display property needs to be set to grid or inline-grid.

Grid containers contain grid items, placed within the columns and rows.

The grid-template-columns Property

The grid-template-columns property specifies the number of columns in the grid layout, and it can specify the width of each column.

The value is a space-separated list, where each value specifies the width of the respective column.

If you want to add grid layout to contain 4 columns, define the width of the 4 columns, or “auto” if all columns should have the same width.

Make a grid with 4 columns:

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

.grid-container > div {
  background-color: grey;
  color:#fff;
  text-align: center;
  padding: 20px 0;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>The grid-template-columns Property</h1>

<p>You can use the <em>grid-template-columns</em> property to specify the number of columns in your grid layout.</p>

<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>
</body>
</html>

				
			

CSS

				
					.grid-container {
  display: grid;
  grid-template-columns: auto auto auto auto;
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

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

Output

The grid-template-columns Property

You can use the grid-template-columns property to specify the number of columns in your grid layout.

1
2
3
4
5
6
7
8

The grid-template-columns property can also be used to specify the size (width) of the columns.

HTML
				
					<h1>The grid-template-columns Property</h1>

<p>Use the <em>grid-template-columns</em> property to specify the size of each column.</p>

<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>
				
			
CSS
				
					.grid-container {
  display: grid;
  grid-template-columns: 80px 200px auto 30px;
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

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

Output

The grid-template-columns Property

Use the grid-template-columns property to specify the size of each column.

1
2
3
4
5
6
7
8

.grid-container {
display: grid;
grid-template-columns: auto auto auto;
grid-template-rows: 80px 200px;
gap: 10px;
background-color: #2196F3;
padding: 10px;
}

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

				
					<h1>The grid-template-rows Property</h1>

<div class="grid-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
  <div>4</div>
  <div>5</div>
  <div>6</div>  
</div>
<p>Use the <em>grid-template-rows</em> property to specify the size (height) of each row.</p>
				
			
CSS
				
					.grid-container {
  display: grid;
  grid-template-columns: auto auto auto;
  background-color: #2196F3;
  padding: 10px;
}

.grid-item {
  background-color: grey;
  border: 1px solid #fff;
  color:#fff;
  padding: 20px;
  font-size: 30px;
  text-align: center;
}
				
			

Output

The grid-template-rows Property

1
2
3
4
5
6

Use the grid-template-rows property to specify the size (height) of each row.

The justify-content Property

The justify-content property aligns the whole grid inside the container.

HTML
				
					<h1>The justify-content Property</h1>

<p>Use the <em>justify-content</em> property to align the grid inside the container.</p>

<p>The value "space-evenly" will give the columns equal amount of space between, and around them:</p>
<div class="grid-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
  <div>4</div>
  <div>5</div>
  <div>6</div>  
</div>
				
			
CSS
				
					.grid-container {
  display: grid;
  justify-content: space-evenly;
  grid-template-columns: 50px 50px 50px; /*Make the grid smaller than the container*/
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

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

Output

The justify-content Property

Use the justify-content property to align the grid inside the container.

The value "space-evenly" will give the columns equal amount of space between, and around them:

1
2
3
4
5
6

Space-around

CSS
				
					.grid-container {
  display: grid;
  justify-content: space-around;
  grid-template-columns: 50px 50px 50px; /*Make the grid smaller than the container*/
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

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

Output

1
2
3
4
5
6

Space-Between

CSS
				
					.grid-container {
  display: grid;
  justify-content: space-between;
  grid-template-columns: 50px 50px 50px; /*Make the grid smaller than the container*/
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

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

Output

1
2
3
4
5
6

Justify Property Center

CSS
				
					.grid-container {
  display: grid;
  justify-content: center;
  grid-template-columns: 50px 50px 50px; /*Make the grid smaller than the container*/
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

.grid-container > div {
  background-color: grey;
  color:#fff;
  text-align: center;
  padding: 20px 0;
  f
				
			

Output

1
2
3
4
5
6
Justify Property Start
CSS
				
					.grid-container {
  display: grid;
  justify-content: start;
  grid-template-columns: 50px 50px 50px; /*Make the grid smaller than the container*/
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

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

Output

1
2
3
4
5
6

Justify-Content end

HTML
				
					.grid-container {
  display: grid;
  justify-content: end;
  grid-template-columns: 50px 50px 50px; /*Make the grid smaller than the container*/
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

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

Output

1
2
3
4
5
6

The align-content Property Center

The align-content property vertically aligns the whole grid inside the container.

CSS
				
					.grid-container {
  display: grid;
  height: 400px;
  align-content: center;
  grid-template-columns: auto auto auto;
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

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

Output

1
2
3
4
5
6

The align-content Property Space-evenly

CSS
				
					.grid-container {
  display: grid;
  height: 400px;
  align-content: space-evenly;
  grid-template-columns: auto auto auto;
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

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

Output

1
2
3
4
5
6

The align-content Property Space-around

CSS
				
					.grid-container {
  display: grid;
  height: 400px;
  align-content: space-around;
  grid-template-columns: auto auto auto;
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

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

Output

1
2
3
4
5
6

The align-content Property Space- Between

CSS
				
					.grid-container {
  display: grid;
  height: 400px;
  align-content: space-between;
  grid-template-columns: auto auto auto;
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

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

Output

1
2
3
4
5
6

The align-content Property Start

CSS
				
					.grid-container {
  display: grid;
  height: 400px;
  align-content: start;
  grid-template-columns: auto auto auto;
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

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

Output

1
2
3
4
5
6

The align-content Property Start

CSS
				
					.grid-container {
  display: grid;
  height: 400px;
  align-content: end;
  grid-template-columns: auto auto auto;
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

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

Output

1
2
3
4
5
6