[英]Anchor hover and adjacent sibling
Imagine this html structure: 想象一下这个html结构:
<p><a></a></p>
<div><a><img></a></div>
I want to hide all images inside a div
after a p tag
, to do that, I simple use this code: 我想在
p tag
后隐藏div
所有图像,为此,我只需使用以下代码:
p + div {display:none;}
but when I try to show those images by hover the anchor
inside the p tag
before, it doesn't work the same way by using this: 但是当我尝试显示通过悬停这些图像
anchor
内部p tag
之前,它不会使用此相同的方式工作:
p > a:hover + div {display:block;}
if I use only p
instead: 如果我只使用
p
代替:
p:hover + div {display:block;}
it works, but it's not what I pretend. 它有效,但这不是我假装的。
Since a
it's a child of p tag
, adjacent sibling "+" doesn't work? 由于
a
是p tag
的子p tag
,因此相邻的兄弟“ +”不起作用吗?
Since a it's a child of p tag, adjacent sibling "+" doesn't work?
由于a是p标签的子元素,因此相邻的同级“ +”不起作用吗?
Correct. 正确。 The
div
is a sibling of the p
, not the a
. 该
div
是的兄弟p
,而不是a
。
You could set pointer-events
for the p
to "none", and pointer-events
for the a
to "auto". 您可以将
p
pointer-events
设置为“ none”,将a
pointer-events
为“ auto”。
You could then use your working p:hover + div
code, but it would act like it's working for the anchor only: 然后,您可以使用工作中的
p:hover + div
代码,但它的行为就像仅对锚点起作用:
p + div { display:none; } p { pointer-events: none; } a { pointer-events: auto; } p:hover + div { display: block; }
<p> <a href="#">This is an anchor.</a> <br> Lorem ipsum et cetera. </p> <div> Cool picture: <a> <img src="http://lorempixel.com/50/50"> </a> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.