本文介绍了选择特定元素之后的所有元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想对某些元素之后的所有元素应用某些特定的样式.例如,我要选择divider
之后的所有元素,并将其背景颜色更改为绿色.
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.
<ul>
<li> Cricket </li>
<li> Hockey </li>
<li class='divider'> </li> //Divider here
<li> Football </li>
<li> Table Tennis </li>
</ul>
CSS代码
li {
background-color: red;
}
//Selector to select elements after divider {
background-color: green;
}
推荐答案
您可以使用
.divider ~ li {
background-color:green;
}
这篇关于选择特定元素之后的所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!