Any idea why ‘li’ elements are not inheriting ‘p’ elements style in the following snippets?
i.e ‘role1’ and ‘role2’ are rendering as black while ‘Hello world!’ and ‘Inside nested p’ are in blue.
<!DOCTYPE html>
<html>
<title>test</title>
<head>
<style type="text/css">
p {
color: blue;
}
</style>
</head>
<body>
<p>
Hello World !
<ol>
<li>role1</li>
<li>role2</li>
</ol>
<p>
Inside nested p
</p>
</p>
</body>
</html>
The p tag can not contain block level elements.
So the browser automaticaly closes the p tag for you.
Your html will parse like this:
And now you see why Hello world and Inside nested p are blue and the li elements are not