0

There's not much to explain, just take a look.

Div No Border:

p {
  background-color: blue;
  border-style: solid;
}

div {
  background-color: red;
}
<div>
  <p>p text</p>
</div>

Output:

Div No Border Output

Div Border:

p {
  background-color: blue;
  border-style: solid;
}

div {
  background-color: red;
  border-style: solid;
}
<div>
  <p>p text</p>
</div>

Output: Div No Border

Why does the red div increase its height when a border is added to it?

j08691
  • 204,283
  • 31
  • 260
  • 272
Joel Castro
  • 485
  • 6
  • 20
  • 2
    you should look up the CSS property `box-sizing`. By default it it is set to `content-box` which means the height is calculated to the height of the content. That does not include padding and border. The next thing is, by adding a border the default margin of the paragraph will be visible as it can't collapse anymore. – tacoshy Nov 16 '22 at 15:52
  • 1
    Worth a watch too: https://youtu.be/qKiz9gdJdr8 – Adam Nov 16 '22 at 15:55
  • Just add a CSS reset, something like this: `* { box-sizing: border-box; padding: 0; margin: 0; }`, add it to every CSS code from now on. – TechTycho Nov 16 '22 at 15:57

0 Answers0