Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE9/8/7 css sprite position slip issue

I want to css sprite (sprite image total width:45px and total height:15px consists of three image ) but there is a problem in IE9/8/7. link and hover work but when click the button (active) sprite image slipping to left 1px. issue for only IE 9/8/7.How can I fix this?

CSS:

body{
    margin:0;
    padding:0;
}

.button{
    background:url(sprite-image.png) no-repeat 0 0;
    width:15px;
    height:15px;
    cursor:pointer;
}

.button:hover{
    background:url(sprite-image.png) no-repeat -15px 0;
}

.button:active{
    background:url(sprite-image.png) no-repeat -30px 0;
}

.cont{
    width:200px;
    height:200px;
    float:left;
    margin:50px 0 0 100px;
}

HTML:

 <body>
  <div class="cont">
     <div class="button">&nbsp;</div>
  </div>
 </body>

"link" and "hover" and "active" FF,Chrome,Safari,Opera like this;

enter image description here

but IE 9/8/7 active look like this;

enter image description here

I concretized above images to make it look better . My sprite image;

enter image description here

like image 713
midstack Avatar asked Dec 25 '12 12:12

midstack


3 Answers

Why not use IE-conditional comments;

 <!doctype html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!-- Consider adding a manifest.appcache: h5bp.com/d/Offline -->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->

And then write eg CSS-rules like .lt-ie9 .someclass{}to target a IE-version. I use them to fix some IE-specific css-stuff. No dirty hacks, no hastle just css. Did you check with eg Firebug Lite what happens?! outline: 0 none?

like image 194
myradon Avatar answered Oct 17 '22 23:10

myradon


Add a Internet explorer specific stylesheet to the <head></head> section.

<!--[if lt IE 9]>
<link rel="stylesheet type="text/css" href="/css/ie.css" />
<![endif]-->

and in ie.css do something like:

.button:active{
    background:url(sprite-image.png) no-repeat -29px 0 !important;
}

(There's Always an issue with ie , phew !)

like image 36
Amyth Avatar answered Oct 17 '22 23:10

Amyth


I created a fake sprite using your graphic to see what you are seeing but looking good in my fiddle in all IE 7-9 (note i just change positioning and made it construsive (less):

http://jsfiddle.net/Riskbreaker/Rr8p2/

body{
    margin:0;
    padding:0;
}

.button{
    background:url(images/sprite.png) no-repeat 0 0;
    width:14px;
    height:15px;
    cursor:pointer;
}

.button:hover{
    background-position:0px -27px;
}

.button:active{
    background-position:0px -27px;
}

.cont{
    width:200px;
    height:200px;
    float:left;
    margin:50px 0 0 100px;
}

Remember the positioning I made up so you can adjust. I never had the active IE issue before...but let me know what you are seeing....if the issue persist and you don't want another file then do this:

IE7: *.button:active{background-position:0px -28px;} (or whatever the correct position is )...

IE8: .button:active{background-position:0px -28px\9;}.........

IE9....not sure your latest but it should not have any issues (latest)

like image 3
Riskbreaker Avatar answered Oct 18 '22 01:10

Riskbreaker