1

I want to stretch the background of an a tag but it doesn't work in Internet Explorer 8. This is the code I'm using:

div.tabbernav div.tabberactive a{
    color:#fff;
    padding:11px;
    background: url(../images/bag_selected.png) ;
    background-size: 100% 100%;
    -moz-background-size: 100% 100%;
    background-repeat: no-repeat;
    height:43px;
}
enenen
  • 1,967
  • 2
  • 17
  • 33
oded
  • 155
  • 1
  • 4
  • 16
  • Stretching images using CSS is most of time a very bad idea. Not only the result is most of time dirty, but the network cost can be higher than a static image of the desired dimension – Steve B Oct 17 '12 at 10:03
  • `a` is an inline tag, have you tried `display:block`? – Andy Oct 17 '12 at 10:03
  • the display:block doesn't help – oded Oct 17 '12 at 10:07
  • Possible duplicate: http://stackoverflow.com/questions/2991623/make-background-size-work-in-ie and a working IE8 example: http://jsfiddle.net/bNEqx/8/ – enenen Oct 17 '12 at 10:12
  • Answer on this ticket http://stackoverflow.com/questions/19415191/scale-background-image-to-fit-ie8-window/19559311#19559311 – manish nautiyal Oct 24 '13 at 07:15

3 Answers3

3

background-size is a CSS3 property and will generally not work in IE8. Also you missed the -webkit- -o- and -ms- prefixes.

That said, there is a way around this using the MS Filters. look at http://www.alistapart.com/articles/supersize-that-background-please/

filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/logo.gif', sizingMethod='scale');

-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/logo.gif', sizingMethod='scale')";

that works with background-size: cover

Naman Goel
  • 1,525
  • 11
  • 16
0

You use this style code

div.tabbernav div.tabberactive a{
    color:#fff;
    padding:11px;
    background: url(../images/bag_selected.png) ;
    background-size: 100% 100%;
    -moz-background-size: 100% 100%;
    background-repeat: no-repeat;
    height:43px;
    filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(
    src='images/logo.gif',
    sizingMethod='scale');

   -ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(
   src='images/logo.gif',
   sizingMethod='scale')";
 }
Saeed
  • 3,415
  • 3
  • 24
  • 41
0

Another cross-browser solution that is JavaScript-based with jQuery is to have something like:

<div id="mystretchedimage"><img src="image.jpg" /></div>

#mystretchedimage { width: 100%; height: 600px; overflow: hidden; }

jQuery('#mystretchedimage img').css({ width: $(window).width() });

Depending on your needs, such as my case, this may be a better solution for you.

Gavin
  • 7,544
  • 4
  • 52
  • 72