ul {
display: inline-block;
list-style: none;
text-align: center;
}
ul::after {
display: table;
content: "";
clear: both;
}
ul:first-child {
background-color: red;
margin-left: 2rem;
}
li {
float: left;
}
<body>
<ul>
<li>House</li>
<li>Dog</li>
</ul>
</body>
With the Code above, find it weird that the :first-child selector (pseudo class) is not working. I would have assumed that the li with House
would have a red background. Instead there is no red background. Do you guys know why?