Google Chrome 和 Safari 中的背景图像问题
这是我的 CSS:
#menu {
float: left;
background: url(images/menu_normal.jpg) repeat-x bottom;
}
#menu li {
display: inline;
float: left;
height: 33px;
line-height: 33px;
text-align: center;
width: 60px;
}
#menu li a:hover {
display: inline;
background: url(images/menu_hover.jpg) repeat-x bottom;
float: left;
height: 33px;
line-height: 33px;
text-align: center;
width: 60px;
}
这是我的 HTML:
<div id = "menu">
<ul>
<li><a href = "#">All</a></li>
<li><a href = "#">Sports</a></li>
<li><a href = "#">Movies</a></li>
<li><a href = "#">Shows</a></li>
<li><a href = "#">Sales</a></li>
<li><a href = "#">Clubs</a></li>
<li><a href = "#">Concerts</a></li>
<li><a href = "#">Parties</a></li>
</ul>
</div>
a:hover
的背景图像在 Chrome 和 Safari 中不显示。
我发现了一些有关 WebKit 的错误,但真的是这样吗?如果是,如何修复?
这是网址: http://eximi.dreamhosters.com/feasibility/statue.html
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会做类似的事情。但是没有一个真实的例子,我很难判断这一点。和迈克尔一样,如果不起作用,请告诉我。
另外,jsFiddle 或指向实际网站的链接会很好。好的,我做了一个例子...
http://jsfiddle.net/dpCwp/
如您所见,您的代码版本在
div#bugged
中无法正常工作,而我的 -div#已修复。是的,他们不使用图像,但正如您所看到的,
#bugged
无论如何都不适用于颜色。以防万一,带有背景图像的工作版本 - http://jsfiddle。 net/dpCwp/3/
嗯,刚刚在 internet-explorer
6/7/8/9
以及最新版本的 opera, safari,chrome, firefox - 就像一个魅力(除了加载远程图像时的延迟..)只是为了做事更清楚...这绝不是与 webkit 或其他什么,这是对 css 的不当使用!
已更新,以反映您的实际 CSS
您的 CSS
必须替换为:
:hover
、:active
伪类中的所有属性,因为这些属性是从#menu li a
继承的,您可以使用你的 CSS 中根本没有。更新 2
所以我刚刚将
#menu
与 Chrome(!您无法使用此功能的浏览器)相关的规则更改为:它工作完美!所以,我要再说一遍,这不是错误,而是无效的 CSS。
I'd do it similar to this.But without a real example, I have hard time judging this. Same as Michael, if doesn't work, let me know.
Plus, jsFiddle or a link to actual site would be nice.Okay, I made an example...
http://jsfiddle.net/dpCwp/
As you can see, there is your version of code in
div#bugged
which is not working and, mine -div#fixed
. Yes, they use no images, but as you can see#bugged
doesn't work with colors anyway.And just in case, a working version with image for background - http://jsfiddle.net/dpCwp/3/
Huh, and just tested on internet-explorer
6/7/8/9
and with newest versions of opera, safari, chrome, firefox — works like a charm (except the delay when loading remote image..)And just to make things clearer... that's in no way a bug related to webkit or whatever, that's improper use of css!
Updated, to reflect your actual CSS
Your CSS
Must be replaced to:
:hover
,:active
pseudo-classes, because those are inherited from#menu li a
, which you don't have at all in your CSS.Update 2
So I just changed
#menu
associated rules with Chrome(! the browser you don't get this working) on-the-go to these:And it works flawlessly! So, I'm going to say it once again, that's no bug, that's invalid CSS.
将
#menu li a:hover
更改为#menu li:hover a
。Change
#menu li a:hover
to#menu li:hover a
instead.经过一番搜索后,它似乎是一个 webkit 错误。也许尝试一下下页提出的方法? http://www.simonday.com/web-design-blog/2010/10/20/css-ahover-not-working-or-crashing-webkit-chrome-safari/
只是将您的代码更改为:
It appears to be a webkit bug upon a bit of searching for it. Perhaps try the method posed at the following page? http://www.simonday.com/web-design-blog/2010/10/20/css-ahover-not-working-or-crashing-webkit-chrome-safari/
Just change your code to:
试试这个:
如果这不能解决问题,请告诉我!
Try this:
If this doesn't fix it, let me know!