我使用
我希望改变
我想到了以下的jquery代码:
:after
伪元素在方块(<li>
)后面显示一个装饰(三角形)。这个想法是区分当前选定的li
和其他li
。
这里有示例代码
以下是HTML代码:<ul>
<li class="active" style="background-color: hsl(108, 60%, 50%)">One</li>
<li style="background-color: hsl(36, 60%, 50%)">Two</li>
<li style="background-color: hsl(252, 60%, 50%)">Three<li>
</ul>
以及 CSS:
ul li {
width: 300px;
height: 30px;
border: 1px dashed;
position: relative;
}
li.active::after {
content: " 0020";
display: block;
font-size: 0px;
position: absolute;
left:100%;
top: 0%;
width: 0px;
height: 0px;
background: transparent;
border: 17px solid transparent;
border-left-color: #FF3900;
}
我希望改变
li.active::after
伪元素的border-left-color
样式属性,使其与具有class=active
的<li>
元素的background-color
匹配。我想到了以下的jquery代码:
$("ul li").click(function() {
$("ul li").removeClass("active");
$(this).addClass("active");
$("li.active::after").css('border-left-color', $(this).css('background-color'));
});
这个没有按预期工作。非常感谢您的帮助。
li.active::active
缺少开头和结尾的"
。 - Albzi:after
伪元素,因为伪元素不会出现在DOM中。 - Richard Peck