是否有一个CSS选择器选择一个元素在当前元素之外? [英] Is there a css selector which selects an element outside the current element?
问题描述
代码解释比字更好
<div class="parent">
<span class="child"></span>
</div>
<div class="outside"></div>
我想做什么
.child:hover ? .outside { }
其中?
selector我正在寻找
where ?
is the selector I'm looking for
推荐答案
选择器表达元素之间的结构关系。当你为另一个元素外部的元素请求一个选择器时,你正在寻找一个组合器,说这个元素出现在这个其他元素的包含范围之外。
Selectors express structural relationships between elements. When you ask for a selector for an element that is "outside" another element, you're looking for a combinator that says "this element appears outside the containing scope of this other element".
没有这样的组合器。
你可以想象具体选择 .outside
sibling of .parent
,但是遇到另一个问题,没有父选择器用于匹配 .parent
相对于 .child:hover
是用于匹配 .child:hover
相对于 .parent
(即 .parent> ; .child:hover
)。
You could conceivably select specifically the .outside
sibling of .parent
, but then you run into another problem that there is no parent selector for matching .parent
relative to .child:hover
like there is for matching .child:hover
relative to .parent
(that is, .parent > .child:hover
).
另请参阅:如何根据页面中另一个元素的状态选择一个元素使用CSS?
这篇关于是否有一个CSS选择器选择一个元素在当前元素之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!