【发布时间】:2015-11-25 05:36:42
【问题描述】:
我无法完全理解这一点。我有以下构造:
<div class="container">
for n = 0 to ...
<a href="some url">Link n</a>
endfor
for each link in ".container"
<div class="poptip"></div>
endfor
</div>
举个例子:
<div class="container">
<a href="some url">Link 1</a>
<a href="some url">Link 2</a>
<a href="some url">Link 3</a>
<div class="poptip">Some content related to link 1 retreived with ajax</div>
<div class="poptip">...</div>
<div class="poptip">...</div>
</div>
现在的障碍是,我试图在锚标记上悬停时显示.poptip,如果有一个链接(通常是这种情况),这显然可以正常工作。在任何情况下,如果有 >1 个链接,那么最后一个链接将起作用。当前的 css(sass 样式)在 >1 种情况下不太适用:
.producttooltip {
position: relative;
}
.producttooltip a:hover + div {
display: block;
}
我无法更改 html 的结构,它始终是容器 > 所有链接后跟所有弹出提示。但是,我可以使用唯一标识符标记弹出提示和锚标记,例如<a href="some url" rel="identifier">Link 1</a><div class="poptip" rel="identifier"></div>,但我不太清楚我在 css 中是否可以创建一个通用选择器(伪):
a:hover + div[rel=a.rel] {
display: block
}
所以我的问题是,我可以用纯 CSS 标记这个结构,还是必须使用一些 JS 技巧(我可以,但我更喜欢 CSS)。希望你们中的一个人比我更聪明。
编辑:只是澄清一下 - 我不能更改 html 的结构。最简洁的解决方案显然是用等效的 poptip 包装每个元素,但我的整个难题是我不能这样做。
【问题讨论】:
标签: javascript jquery html css