CSS 选择特定元素后的所有元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17106089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:12:51 来源:igfitidea点击:
Select all elements after specific element
提问by sachinjain024
I want to apply some specific styles to all elements which come after a certain element. For example, I want to select all elements which come after the divider
and change their background color to green.
我想对某个元素之后的所有元素应用一些特定的样式。例如,我想选择 之后的所有元素divider
并将它们的背景颜色更改为绿色。
<ul>
<li> Cricket </li>
<li> Hockey </li>
<li class='divider'> </li> //Divider here
<li> Football </li>
<li> Table Tennis </li>
</ul>
CSS code
CSS代码
li {
background-color: red;
}
//Selector to select elements after divider {
background-color: green;
}
回答by Zero Fiber
You can use
您可以使用
.divider ~ li {
background-color:green;
}