【发布时间】:2022-01-27 07:32:29
【问题描述】:
我有一个列表,我想为奇数、偶数和最后两个子元素应用颜色。 我的结果很糟糕,最后两个孩子影响了奇怪的元素!
ul {
list-style-type: none;
display: inline-block;
text-align: center;
width: 100%;
margin: 0;
}
ul:last-child(n-2) li{
background-color:blue}
li {
height: 25px;
width: 25px;
border-radius: 50%;
display: inline-block;
}
li:nth-child(even) {
background-color: red;
}
li:nth-child(odd) {
background-color: green ;
}
<!DOCTYPE html>
<html>
<head>
<title>Christmas tree</title>
</head>
<body>
<div>
<ul>
<li></li>
</ul>
<ul>
<li></li>
<li></li>
</ul>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<ul>
<li></li>
</ul>
<ul>
<li></li>
</ul>
</div>
</body>
</html>
【问题讨论】:
-
完全不清楚您现有的代码有什么问题。哪些孩子的颜色不对,他们应该是什么颜色?
-
它基本上是一棵带有几个红色和蓝色小玩意的绿树吗?哪些?
标签: html css css-selectors