我不明白哪一个是第一类型,最后一个孩子和最后一个类型?
<!doctype html>
<html>
<head>
<style>
:first-cild{color:green;}
</style>
</head>
<body>
<div>
<ul>
<li> <a href="#"> One</a> </li>
<li> <a href="#"> Two </a> </li>
<li> <a href="#"> Three</a> </li>
</ul>
<p> This is a paragraph</p>
</div>
</body>
</html>
答案 0 :(得分:3)
通过尝试找出它们,看看会发生什么!
:first-child
{
border:solid thin green;
}
ul:first-child
{
border:solid thin blue;
}
li:first-of-type
{
border:solid thin red;
}
li:last-of-type
{
border:solid thin orange;
}
<!doctype html>
<html>
<body>
<div>
<ul>
<li> <a href="#"> One</a> </li>
<li> <a href="#"> Two </a> </li>
<li> <a href="#"> Three</a> </li>
</ul>
<p> This is a paragraph</p>
</div>
</body>
</html>