I was drafting a quick test of how styling works in nested lists in HTML and CSS. I was trying to showcase how the child selector works in difference to the general decendant selector (don't know if that's the correct term) ul li, vs ul > li.
But when I put color red on ul > li, then ONLY the child li in the ul SHOULD get red colored text, but turns out that all text in ul inherits that color. Could someone be so kind and explain to me why this happens with only text properties, for example color, text-align and text-decoration. While properties like background-color and border doesn't get passed down to the grandchildren (as it correctly should work with > selector). Or just send me a link to somewhere where this is explained!
Thanks in advance!
ul {
background-color: red;
}
ul li {
background-color: green;
}
ul>li {
background-color: blue;
color: red;
text-align: center;
}
ul>li>ol {
background-color: pink;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Test</title>
<link href="styles.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" rel="stylesheet" />
</head>
<body>
<div>
<ul>
Unsorted List
<li>
First Items In Unordered List
<ol>
First Ordered List
<li>First Ordered Item</li>
<li>Second Ordered Item</li>
<li>Third Ordered Item</li>
</ol>
</li>
<li>
Second Item In Unordered List
<ol>
Second Ordered List
<li>First Ordered Item</li>
<li>Second Ordered Item</li>
<li>Third Ordered Item</li>
</ol>
</li>
<li>
Third Item In Unordered List
<ol>
Third Ordered List
<li>First Ordered Item</li>
<li>Second Ordered Item</li>
<li>Third Ordered Item</li>
</ol>
</li>
</ul>
</div>
</body>
<script src="script.js"></script>
</html>