html、div、css - 悬停 Action 和背景图像更改

标签 html css background hover

#logo
{
    position: relative;
    width: 100px;
    height: 18px;
    float: right;

    background-image: url('../images/logo_def.png');
    background-repeat: no-repeat;
    background-position: 50% 50%;
}

#logo a:hover
{
    background-image: url(../images/logo_h.png);
} 

它可以工作,但是当鼠标悬停在它上面时 bg-image 并没有改变,为什么?

最佳答案

那么,眼前的问题是没有 <a>里面的元素#logo .更改第二条规则以定位正确的元素将“解决”此问题:

#footer a:hover
{
    background-image: url(../images/logo_h.png);
}

编辑:
正如评论中指出的那样:

The style of the first rule should be applied to the A element and the #logo DIV should be removed since it serves no purpose whatsoever.

这确实是解决您的问题的更好方法,因为它会减少困惑并有助于防止将来出现更多令人头疼的问题。 (感谢@Julian 的澄清)

关于html、div、css - 悬停 Action 和背景图像更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1461409/

相关文章:

php - jQuery 自动完成 - 隐藏 php 请求页面内容

javascript - 在 SVG 中显示流运动的最佳方式?

html - div 没有完全扩展到内容

html - 在使用透明 Sprite 时给 A#Logo 一个背景颜色?

c# - 在 Mac 上使用 C#/Mono 的仅系统托盘(无停靠图标)应用程序

javascript - 如何在 Node 中的文本中替换/注入(inject) html 标签?

php - 将 HTML 转换为 PHP 时,CSS 'active' 不起作用

HTML/CSS 问题

html - 如何让背景显示完整图像

javascript - 使用 Jquery 或 JS 添加和删除 div