Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background CSS image no showing in IE7 only

The html is:

<div class="choose-os">
<p>
   <a href="someLink" class="windows">Microsoft Windows</a> 
   <a href="someOtherLink" class="macos">Apple Mac OS</a>
</p>
</div>

The CSS is:

.choose-os {
    margin: 20px 0;
    padding: 20px;
    background: #e7eefa;
}
.choose-os p {
    margin: 0;
}
.choose-os p a {
    display: inline-block;
    text-indent: -100000px;
    height: 56px;
    width: 308px;
}
.choose-os p a.windows {
    background: url(../images/button-windows-bg.png) 0 0;
}
.choose-os p a.macos {
    background: url(../images/button-macos-bg.png) 0 0;
}
.choose-os p a:hover {
    background-position: 0 -56px;
}

Any suggestions would be greatly appreciated as to have the background image also appear on IE7.

like image 419
Stephane Grenier Avatar asked Jul 17 '11 19:07

Stephane Grenier


1 Answers

The text-indent: -100000px; in combination with inline-block is what's causing the two elements to not be visible in IE7, due to a bug.

You need to find some other way to hide the text for IE7 (or not use inline-block at all, see below for this more suitable fix).

Options include the method in the comment by @Sotiris, or:

.choose-os p a {
    display: inline-block;
    height: 56px;
    width: 308px;

    text-indent: -100000px;

    /* for ie7 */
    *text-indent: 0;
    *font-size: 0;
    *line-height: 0
}

Which uses the *property: value hack several times to hide the text in IE7.


The problem does seem to be related to the use of display: inline-block.

So, another workaround (which I prefer to my previous one) is:

.choose-os {
    margin: 20px 0;
    padding: 20px;
    background: #e7eefa;
    overflow: hidden
}
.choose-os p a {
    float: left;
    margin-right: 4px;
    text-indent: -100000px;
    height: 56px;
    width: 308px;
}
like image 170
thirtydot Avatar answered Nov 12 '22 22:11

thirtydot