html - 无法让背景图片悬停在图片上

标签 html hover position css

我正在尝试将带有标题的透明 PNG 悬停在照片上。当我给 div position: absolute 或指定的宽度时,悬停消失了。但是,如果我不这样做,则悬停会显示在图像的右侧和左侧。

我显然做错了什么,但无法弄清楚是什么。任何帮助,将不胜感激。

谢谢!

这是网站和相关代码。

网站:http://www.theshalomimaginative.com/

<div id= "logo">
 <h3><img src="Graphics/splashpagelogo.png"  alt="The Shalom Imaginative Documentary Photography" /></h3>
</div>


#logo {
position:absolute; width:475px; height:365px; padding: 0 0 0 242px;
}   

h3 {
position:absolute; width:475px; height:365px;display: block;
}

h3:hover {
position:absolute; width:475px; height:365px; display: block; background-image:   url('http://theshalomimaginative.com/Graphics/Homepagehover.png');
}

最佳答案

我马上看到的一个问题是您没有正确关闭标签。

代替

</logo>

应该是:

</div>

您可以这样做:

<div id="logo">

</div>

#logo {
    position:absolute;
    width:475px;
    height:365px;
    padding: 0 0 0 242px;
    background: url('http://theshalomimaginative.com/Graphics/splashpagelogo.png') no-repeat;

} 

#logo:hover {
    position: absolute;
    width:475px;
    height:365px;
    background: url('http://theshalomimaginative.com/Graphics/Homepagehover.png') no-repeat;    
}

http://jsfiddle.net/tech0925/SW7GP/

如果您想为了 SEO 目的包含 h3 标签,您可以这样做:

<div id="logo">
<h3>Something Here</h3>
</div>

#logo {
    position:absolute;
    width:475px;
    height:365px;
    padding: 0 0 0 242px;
    background: url('http://theshalomimaginative.com/Graphics/splashpagelogo.png') no-repeat;

} 

#logo:hover {
    position: absolute;
    width:475px;
    height:365px;
    background: url('http://theshalomimaginative.com/Graphics/Homepagehover.png') no-repeat;    
}

#logo h3 {
text-indent: -9999px;
}

http://jsfiddle.net/tech0925/YnMeD/

关于html - 无法让背景图片悬停在图片上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14484474/

相关文章:

html - 是否可以为 DIV 设置 "Minimum Distance from Left"值?

javascript - Firebug : TypeError: 'click' called on an object that does not implement interface HTMLElement

java - 避免使用 Java 编写 HTML

html - 有没有办法将 SWF 转换为 HTML5

html - 你能在 IE 中的表格行上放置渐变吗?

css - 带悬停的菜单,如何在移动设备上工作?

html - 如何选择具有两个类的元素?

css - 没有循环悬停的视频

html - 裁剪出css图片容器

css - 没有指定顶部、右侧、底部、左侧等的绝对定位元素的行为