Tiles in Grid in CSS

Let's move on to practical work with the grid system and create tiles with different indents.

Tiles of 9 blocks, 3 in a row, without indentation

Let's create a table with nine elements and arrange them into three columns:

html<div id="parent">
  <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>
css#parent {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 2px solid #696989;
  padding: 10px;
  width: 600px;
}
#parent > div {
  height: 100px;
  padding: 10px;
  border: 1px solid #696989;
}

Результат:

Tiles of 9 blocks, 3 in a row with indents

Now let's apply the grid-gap property to create some space between the elements:

html<div id="parent">
  <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>
css#parent {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 10px;
  border: 2px solid #696989;
  padding: 10px;
  width: 600px;
}
#parent > div {
  height: 100px;
  padding: 10px;
  border: 1px solid #696989;
}

Результат:

Tiles of 9 blocks, 3 in a row, with spaces only between blocks

Now let's set the distance only between blocks in the grid:

html<div id="parent">
  <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>
css#parent {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 10px;
  border: 2px solid #696989;
  width: 600px;
}
#parent > div {
  height: 100px;
  padding: 10px;
  border: 1px solid #696989;
}

Результат:

A tile of 8 blocks, 3 in a row, with a missing block

Let's make a tile where one block is missing in the bottom row:

html<div id="parent">
  <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#parent {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 10px;
  border: 2px solid #696989;
  width: 600px;
}
#parent > div {
  height: 100px;
  padding: 10px;
  border: 1px solid #696989;
}

Результат:

Practical tasks

Задание 1

Implement the following example:

Задание 2

Implement the following example:

Задание 3

Implement the following example: