CSS悬停图像位置更改

2023-12-28

我确信这是超级愚蠢的事情,但现在我已经被困了一段时间......所以,我在网站上有图像,我希望它们在悬停时稍微移动。

所以我在 HTML 中有:

<a href="someaddress"><img class="thumb" src="somefile"/></a>

在 CSS 中:

img.thumb {
    position:relative;
    top:0px;
    background:#333399;

}

img.thumb:hover {
    position:relative;
    top:5px;    
    background:#00CCCC;

}

背景只是为了看看是否有事情发生。实际上,背景不会改变,因此悬停永远不会被考虑在内。有谁知道为什么会这样?

EDIT

非常感谢大家!

我实际上通过添加以下内容解决了这个问题:

a > img.thumb:hover {
position:relative;
top:2px;
}

这有效。仍然不确定为什么它不能仅与 img.thumb:hover 一起使用...


这里是solution http://jsfiddle.net/KTpRE/.

HTML:

<div>
<a href="someaddress"><img class="thumb" src="http://www.google.co.in/images/srpr/logo4w.png"/></a>
</div>

The CSS:

img.thumb {
    position:relative;
    top:0px;

}

img.thumb:hover {
    position:relative;
    top:5px;    
    background:#00CCCC;

}

我希望这有帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CSS悬停图像位置更改 的相关文章