[英]What is the css selector for a nephew?
I have a series of elements with the following html format:我有一系列具有以下 html 格式的元素:
<div class="wrap">
<div class="hoverArea"> ... </div>
<div class="caption"> ... </div>
<div class="image"> ... </div>
</div>
with.hoverArea, .caption, .image { position: absolute; with.hoverArea,.caption,.image { position:绝对; }
}
When user hovers over the 'hoverArea' the (sibling) image enlarges with:当用户将鼠标悬停在“hoverArea”上时,(兄弟)图像会放大:
.hoverArea:hover ~.image { width: 300px; .hoverArea:hover ~.image { 宽度:300px; }
}
This worked fine, but I now need to put the image in a parent/wrapper这工作正常,但我现在需要将图像放在父/包装器中
<div class="wrap">
<div class="hoverArea"> ... </div>
<div class="caption"> ... </div>
<div class="parent">
<div class="image"> ... </div>
</div>
</div>
What is the selector I need for the nephew?侄子需要什么选择器? I thought it was just:
我以为只是:
.hoverArea:hover.image { width: 300px; .hoverArea:hover.image { 宽度:300px; }
}
Or或者
.wrap.hoverArea:hover.parent.image {... } .wrap.hoverArea:hover.parent.image {... }
But these doesnt seem to work.但这些似乎不起作用。
And would it be any different if I was to add the parent with a '::before'?如果我用'::before'添加父级会有什么不同吗?
try this尝试这个
~
: for sibling selector ~
: 兄弟选择器>
: for child selector >
: 用于子选择器
In Sentence, .hoverArea
's sibling is .parent
and it's child is .image
在句子中,
.hoverArea
的兄弟是.parent
而它的孩子是.image
.hoverArea:hover ~ .parent > .image{
width: 300px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.