jQuery:我可以使用 z-index 来解决这个问题吗?
在讨论这个问题之前,我认为最好描述一下我正在尝试做的事情......如果你转到这个小提琴,你可以在行动中看到它(尽管存在问题):
http://jsfiddle.net/jhacks/xCcdn/99/ (需要选择 jQuery 才能工作
)问题我是试图通过这篇文章解决问题是相当公然搞砸了。由于我的 html 的顺序,工具提示 (topTip) 会在通知图标 (topIconNew) 出现时将其向下推送。显然,通知图标应该保持静止。我不想重新排序 html,因为通知图标并不总是存在。因此,它们都可以使用同一个类来定位。我认为解决方案应该是z-index?然而,我尝试使用 CSS 来解决它似乎不起作用......我想也许我必须在 jQuery 中做一些事情?
如果有人能在这里帮助我,我将不胜感激。如果我需要更清楚地了解我想要在这里做什么,请告诉我,我会尽力更好地解释。谢谢!
Before going into the problem, I thought it'd be best to describe what I'm trying to do... if you go to this fiddle you can see it in (although with problems present) in action:
http://jsfiddle.net/jhacks/xCcdn/99/ (it needs to have jQuery selected to work)
The problem I'm trying to solve with this post is pretty blatantly screwed up in the fiddle. Due to the ordering of my html, the tooltip (topTip) pushes the notification icon (topIconNew) downwards when it is present. Obviously, the notification icon should remain stationary. I do not want to reorder the html, as the notification icon will not always be present. Therefore, they can all be positioned using the same class. I think the solution should be z-index? However, my attempts at using CSS to solve it don't seem to work... I assume there is something I must do in the jQuery perhaps?
If anyone could help me here it'd be greatly appreciated. Let me know if I need to be more clear with what I'm looking to do here and I'll try to better explain. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将
.topTip
的两个 CSS 属性更改为以下内容:并将此 CSS 属性添加到
.topIcon
:更新了 jsFiddle
Change the two CSS properties of
.topTip
to these:And add this CSS property to
.topIcon
:Updated jsFiddle
我希望我能正确地回答这个问题。我建议使用绝对定位来使图标在显示工具提示时保持在原来的位置。您还应该将 .topIcon 位置设置为“相对”,以便工具提示的绝对位置与其相关。变化会有点像这样。 (不确定该职位的实际人数。
I hope I get the question correctly. I would recommend to use absolute positioning to keep the icons where they are when the tooltip is shown. You should also set the .topIcon position to 'relative' so the absolute position of the tooltip relates to it. The changes will be somewhat like this. (Not sure about the actual numbers for the position.
也许尝试一下: http://jsfiddle.net/sdPVG/
我已经添加了负边距补偿框高度和边框宽度。这看起来有点hackish,但实际上在许多不同的浏览器上都得到了很好的支持。
希望有帮助!
Perhaps give this a try: http://jsfiddle.net/sdPVG/
I've added a negative margins to compensat for the box height and border width. This seems a bit hackish, but is actually very well supported across many different browsers.
Hoep that helps!
更改
为
还添加了 .topIconOld 作为间隔符,如果您不这样做,则不会使用红色图标来保留间距。希望您能在此fiddle中看到这是我第一次使用它来共享等:- )
change
to
also added .topIconOld as spacer for where you don't won't red icon to preserve spacing. Hopefully you'll see in this fiddle it's the first time I have used it for sharing etc :-)