-1

I've stumbled upon <div> behavior I've never noticed.

<div> doesn't inherit text formatting styles from the <p> tag. Only from the <p> tag. Even when using class selector.

https://codepen.io/elaman/pen/JjjRvWB

Is there any documented explanation to this?

Elaman
  • 851
  • 1
  • 10
  • 22

3 Answers3

0

Use this CSS

p, a, section, .test ,div{
  text-decoration: underline;
  font-weight: bold;
  color: blue;
  font-size: 12px;
}
0

Nesting div tags within p tags is invalid in HTML. If you open this in the browser and click inspect elements you'll see that the browser is creating 2 p tags on either side of the div and it is no longer nested. So the div cannot inherit anything from a p tag.

craft9861
  • 204
  • 2
  • 8
0

As per W3 validation, this is not a valid p tag not contain div element. so check in inspect or view page source div tag is outside of p automatically that's why p tag style did not apply on div tag.

Keyur Gajjar
  • 350
  • 2
  • 7