Rebuilding Blocks via Media Queries in CSS

Let's learn how to rebuild blocks on different screen widths. For example, let's implement the following behavior:

First, let's write the HTML code for our blocks:

html<div class="parent">
  <div class="child">1</div>
  <div class="child">2</div>
</div>

Now let's write styles for the parent of our blocks:

css.parent {
  display: flex;
  width: 90%;
  margin: 50px auto;
  border: 1px solid red;
}

Now let's write styles for the blocks themselves, without specifying the properties that will be changed by media queries:

css.child {
  box-sizing: border-box;
  padding: 20px;
  border: 1px solid green;
}

On large screen widths, let the gap between blocks be calculated automatically:

css@media (min-width: 500px) {
  .parent {
    justify-content: space-between;
  }
}

Let's set the width of our blocks to slightly less than 50% to leave some space for indentation:

css@media (min-width: 500px) {
  .child {
    width: 49.5%;
  }
}

On a small screen width, we'll place our blocks in a column:

css@media (max-width: 500px) {
  .parent {
    flex-direction: column;
  }
}

Let's give them a bottom indent:

css@media (max-width: 500px) {
  .child {
    margin-bottom: 10px;
  }
}

Let's put it all together and get the following code:

css.parent {
  display: flex;
  width: 90%;
  margin: 50px auto;
}
.child {
  box-sizing: border-box;
  padding: 20px;
  border: 1px solid green;
}

@media (max-width: 500px) {
  .parent {
    flex-direction: column;
  }
  .child {
    margin-bottom: 10px;
  }
}
@media (min-width: 500px) {
  .parent {
    justify-content: space-between;
  }
  .child {
    width: 49.5%;
  }
}
Задание 1

Repeat the example below:

Задание 2

Repeat the example below:

Задание 3

Repeat the example below:

Задание 4

Repeat the example below: