简体   繁体   English

CSS Sprite仍在发出新请求

[英]CSS Sprites still making new requests

I am using CSS sprites however when i hover over it is making another request for the same image and causing a flicker. 我正在使用CSS精灵,但是当我将鼠标悬停在其上时,它会再次请求同一张图片并导致闪烁。 Any idea why its making 2 requests? 知道为什么要发出2个请求吗? Here is my code: 这是我的代码:

.btn-red-lrg .left {background:url(../images/site-sprite.png) no-repeat 0px 0px transparent;width: 9px;}     
.btn-red-lrg:hover .left {background:url(../images/site-sprite.png) no-repeat 0px -37px transparent;width: 9px;}

Dont' use the background -shorthand property. 不要使用background -shorthand属性。 Use background-position instead, since you only want to update the position. 请改用background-position ,因为您只想更新位置。

/* no need for width, background-image etc. */
.btn-red-lrg:hover .left {background-position: 0px -37px;}

Specifying a background-image:url(...) on the :hover pseudo-class can result in a new request if the caching mechanism aren't sufficient or the expiration date is missing/wrong (see Jeff's answer ). 如果缓存机制不足或到期日期丢失/错误(请参阅Jeff的回答 ),则在:hover伪类上指定background-image:url(...)可能会导致新的请求。 Altering the position only won't result in a new request regardless of the browser. 无论使用哪种浏览器,更改位置都不会导致新的请求。

What browser are you using? 你使用的是什么浏览器? This is a known bug in using Internet Explorer 6. The solution is to add expires headers to the image on the server. 这是使用Internet Explorer 6的一个已知错误。解决方案是将过期标头添加到服务器上的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM