Practices for using em in CSS

Let's look at the full HTML code of the page:

html<html>
  <head>
    <title></title>
  </head>
  <body>
    <main>
      <div>
        <p>
          text
        </p>
      </div>
    </main>
  </body>
<html>

By default, all page tags have some font size. In fact, the html tag has some font size by default:

csshtml {
  font-size: 16px; /* default value */
}

So we can give page tags sizes in em, and they will calculate their sizes relative to their immediate parents.

Let's, for example, specify the font size for the tag main:

cssmain {
  font-size: 1.5em; /* corresponds to 24px */
}

Now let’s specify the font size for the tag div:

cssdiv {
  font-size: 2em; /* corresponds to 48px */
}
Задание 1

Let's say we have HTML code for which we will solve problems:

html<main>
  <h1>header</h1>
  <div>
    <p>
      text
    </p>
    <p>
      text
    </p>
  </div>
  <div>
    <p>
      text
    </p>
    <p>
      text
    </p>
  </div>
</main>

In all the problems below, rewrite all units specified in pixels into em:

Задание 2
cssmain {
  margin: 16px auto;
}

h1 {
  font-size: 32px;
}
p {
  font-size: 32px;
}
Задание 3
cssmain {
  margin: 32px auto;
}

h1 {
  font-size: 32px;
}
div {
  font-size: 16px;
  margin-bottom: 32px;
}
p {
  font-size: 20px;
}