悬停时在 td 中显示图像
这是我想要实现的目标(不确定是否可能):
将鼠标悬停在 td 上,然后在该 td 的右下角(可能与单元格边框重叠)显示一个小图像。
我对 jQuery 没问题,所以我可以处理悬停,但 CSS 却让我头疼。如何定位图像?我是否会在每个单元格中都有图像,并且仅在悬停时显示它?或者有更好的方法吗?
我用的是IE7。我很感激任何指导。
Here is what I am trying to achieve (not sure if it's even possible):
Hover the mouse over a td, and in the bottom right corner of that td (perhaps overlapping the cell border), show a small image.
I'm okay with jQuery, so I can handle the hovering, but the CSS kills me. How do I position the image? Would I have the image in every cell, and only show it on hover? Or is there a better way?
I'm on IE7. I appreciate any guidance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了避免将图像放入页面中的每个 td 中,您还可以使用背景图像:
使用初始偏移量的原因是,它确保图像与页面一起预加载,因此在第一个过程中不会出现延迟鼠标悬停。
浏览器支持问题
我不确定不同浏览器对定位方向的支持程度如何,您可能还需要查看本文以确保 :hover 伪类在您的目标浏览器中正常工作。 IE7+ 将支持 :hover 伪类,但它们需要正确的文档类型(以及良好的盛行风)
http://www.bernzilla.com/item.php?id=762
使用 jQuery 代替
如果您不想使用 :hover 您可以坚持使用 jquery 来添加和删除类。等效的 CSS 是:
其中“.hoverclass”是您在鼠标悬停期间添加到 td 的类名。
To avoid putting an image into every single td in the page you could also use a background image:
The reasoning for using the initial offset is that it makes sure that the image is pre-loaded with the page and so there's no lag during the first mouseover.
Browser support issues
I'm not sure how well supported the positioning directions are for different browsers and you may also want to check out this article to make sure that the :hover pseudo class works correctly for your target browsers. IE7+ will support the :hover pseudo class but they need the correct doctype (and a good prevailing wind)
http://www.bernzilla.com/item.php?id=762
Using jQuery instead
If you don't want to use :hover you can stick to jquery to add and remove a class. The equivalent CSS for that would be:
where ".hoverclass" is the classname that you add to the td during the mouseover period.
类似的事情会在 td 中显示和隐藏图像。
Something along the lines of this will show and hide images in a td.
要进行定位,需要使用绝对定位。 CSS 应该是:
HTML 应该类似于:
To do the positioning, what you want to use is absolute positioning. The CSS would be:
The HTML should be similar to: