-1

I'm trying to make the div symmetrically spaced but when I increase the font size to 200% or 32px, the lower padding, which is of 3em and the <body> tag's margin of 3 em gets mismatched due to it getting longer in the bottom The screenshot

<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body style="margin-left: 5px;
margin-right: 5px;
margin-top: 3em;">
  <div style="text-align: center; padding-bottom: 3em; font-size:32px;">Lorem ipsum dolor sit amet</div>
  <div style="font-size: 55px; background-color: #000000; color: #FFFFFF;">Lorem Ipsum Dolor Sit Amet</div>
</body>

</html>
AStombaugh
  • 2,930
  • 5
  • 13
  • 31
  • 1
    Of course they won't match any more, because they are calculated based on different font sizes now. Put the margin-top on the first div instead of body then, so that both margin and padding are based on the same font size ...? – CBroe Apr 29 '22 at 11:33
  • @CBroe Thanks a lot! I didn't know the scaling function of the em unit – Active-leopard-58a51d Apr 29 '22 at 11:35

1 Answers1

0

As you have used em and em is related to font size here is a definition em: Relative to the font size of the element (2em means 2 times the size of the current font)

As you make changes by em it will affect the padding and margin based on that