CSS Sprites仍在提出新请求

Sco*_*a P 1 css performance css-sprites

我正在使用CSS sprites但是当我将鼠标悬停在它上面时,它会再次请求同一图像并导致闪烁.知道为什么要提出2个请求吗?这是我的代码:

.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;}
Run Code Online (Sandbox Code Playgroud)

Zet*_*eta 5

不要'使用background-shorthand属性.请background-position改用,因为您只想更新位置.

/* no need for width, background-image etc. */
.btn-red-lrg:hover .left {background-position: 0px -37px;}
Run Code Online (Sandbox Code Playgroud)

如果缓存机制不足或失效/错误的过期日期,则background-image:url(...):hover伪类上指定a 可能会导致新请求(请参阅Jeff的回答).无论浏览器如何,仅改变位置都不会产生新的请求.