CSS Sprite is not loading sprites correctly -


i'm trying load spritesheet menu i'm building, instead of showing 1 image @ time, shows whole spritesheet @ different positions in element.

this css code using 2 images:

#mymenu ul.menu > li > a.haschild {     background: #000 url("../images/right.png") no-repeat right center; }     #mymenu ul.menu > li:hover > a.haschild     {         background: #000 url("../images/right-hover.png") no-repeat right center;     } 

this i've tried use spritesheet:

#mymenu ul.menu > li > a.haschild {     background: #000 url("../images/spritesheet.png") 0px 0px no-repeat right center; }     #mymenu ul.menu > li:hover > a.haschild     {         background: #000 url("../images/spritesheet.png") -6px 0px no-repeat right center;     } 

but shows both images @ same time (the whole spritesheet)

i've tried:

#mymenu ul.menu > li > a.haschild {     background: #000;     background-image: url("../images/spritesheet.png") 0px 0px no-repeat right center; }     #mymenu ul.menu > li:hover > a.haschild     {         background: #000;             background-image: url("../images/spritesheet.png") -6px 0px no-repeat right center;     } 

same result...

what doing wrong ?

edit

this jsfiddle:

http://jsfiddle.net/hkasw/

you have think of this: you're applying background image element quite large. css doesn't know background image sprite; displays background image other background image. , in case, icons right next each other on image, displayed whole. cannot crop part of background image using css, either need include ample padding in sprite account size of element (tricky, because may want use icons on larger elements, unknown), or include elements in markup fit exact size of icons, add icon sprite them (more foolproof, markup sucks).

here's example of code, , removed of extraneous css (i'm sure can optimised further, we're working on icons here). don't need define icon class on both parent , sub-menu items; can re-use icon class. that's point of css!

a.haschild {   background: #000 url("http://www.grouctivity.com/menu/sprites.png") no-repeat 0 0; }  a.haschild:hover {   background-position: -6px 0; } 

here's jsfiddle demo of icon elements: http://jsfiddle.net/hkasw/2/


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -