能百度到的有 >和+这样的符号,分别控制子元素、下一个兄弟元素。
如
<html>
<body>
<style>
#a {color : #FFFF00;}
#a:hover > #b{color : #FF0000;}
#a:hover + #c{color : #00FF00;}
#a:hover + #c > #b{color : #0000FF;}
</style>
<p id='a'>元素1
<p id='b'>元素2</p>
</p>
<p id='c'>元素3
<p id='b'>元素2</p>
</p>
</body>
</html>
我想知道的是,有没有更多这样的符号?比如能实现选择上一个兄弟元素?
It won’t work if you only use css. The css selector selects downwards and cannot select upwards. You can try sass or js;;;
If you must select an element (a) through css To control another element (b), you can only make b a child element of a or put it behind a
There is no direct solution, but there are several other CSS3 pseudo-classes that may solve some problems.
p:first-of-type
: Specify the background color of the first p element of the parent element#a~#c:hover
: The c element must have a above it.Feel it:
Thank you for the invitation
http://www.runoob.com/cssref/... This can help you a lot
It can be said to be a logical problem...
Selecting child elements or next sibling elements is based on the current element. To select the "previous sibling element", you can choose to use the "previous sibling element" as a reference and give a class or id, then the "current element" will be the "next sibling element". . .
The functions that can be implemented using + and > do not need to define many similar pseudo-class selectors, and it is easy to confuse them in memory.