Subgrids in CSS

A subgrid is a variation of a nested grid, but unlike it, it affects the size of the parent grid container. To set a subgrid, you need to set the display property in the child element itself with a value of subgrid.

For example, let's create a nested grid in the fourth element:

html<div id="parent">
  <div id="elem1">1</div>
  <div id="elem2">2</div>
  <div id="elem3">3</div>
  <div id="elem4">
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
  </div>
</div>
css#parent {
  display: grid;
  grid-template: 1fr 1fr / 1fr 1fr;
  grid-gap: 5px;
  border: 2px solid #696989;
  padding: 10px;
  width: 600px;
  height: 200px;
}
#parent > div {
  padding: 10px;
  border: 1px solid #696989;
}
#elem4 {
  display: subgrid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  grid-gap: 5px;
  border: 2px solid #696989;
  padding: 5px;
}
#elem4 > div {
  grid-gap: 5px;
  padding: 6px;
  box-sizing: border-box;
  border: 1px solid #696989;
}

Результат:

Задание 1

Let's say you have a grid consisting of five elements arranged in two columns. Create a nested grid in the third element, which in turn will have two child elements.

Задание 2

Modify the previous task so that the nested grid has four children.

Задание 3

Create two nested grids - in the second element and the fifth element.