# Some CSS help.  IE (8) strange behaviour.

**URL:** https://boards.straightdope.com/t/some-css-help-ie-8-strange-behaviour/511285
**Category:** Factual Questions
**Created:** [September 23, 2009, 8:19pm UTC](https://boards.straightdope.com/t/some-css-help-ie-8-strange-behaviour/511285 "2009-09-23T20:19:44Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 23, 2009, 8:19pm UTC](https://boards.straightdope.com/t/some-css-help-ie-8-strange-behaviour/511285/1 "2009-09-23T20:19:44Z")

</div>

I have some CSS designed to cause a link’s background to go grey when it’s hovered over…

small a:hover, a:hover {background-color: #CCC;}

In Firefox it works fine.  
In IE it works fine for text links. But for Image links it does something strange. It causes a grey box to appear behind, at the bottom, and slightly to the left of the image. Look at [http://notails.com](http://notails.com) in IE 8 to see what I mean. (Compare with same in Firefox, if you have it)

So my question is, how do I stop image links from inheriting the behaviour of text links?

(I want to ‘undo’ the hover behaviour for image links)

---

<div class="post-metadata">

### Author: ![Duckster](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/duckster/32/1244_2.png) [@Duckster](https://boards.straightdope.com/u/Duckster)
#### Post date: [September 23, 2009, 10:06pm UTC](https://boards.straightdope.com/t/some-css-help-ie-8-strange-behaviour/511285/2 "2009-09-23T22:06:11Z")

</div>

Assign specific CSS to links vs images.

Also, be aware of [CSS LoVe/HAte" Linking](http://www.d.umn.edu/itss/support/Training/Online/csstips/lovehate.html).

---

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 23, 2009, 10:13pm UTC](https://boards.straightdope.com/t/some-css-help-ie-8-strange-behaviour/511285/3 "2009-09-23T22:13:15Z")

</div>

> [@Duckster](#):
>
> Assign specific CSS to links vs images.
> 
> Also, be aware of [CSS LoVe/HAte" Linking](http://www.d.umn.edu/itss/support/Training/Online/csstips/lovehate.html).

If I assign CSS to a link, it applies the same CSS to a linked image. I don’t know how to NOT do that.

How do I assign specific CSS to an image that would override the link CSS and stop the strange behaviour?

---

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 23, 2009, 10:59pm UTC](https://boards.straightdope.com/t/some-css-help-ie-8-strange-behaviour/511285/4 "2009-09-23T22:59:05Z")

</div>

I got the answer. Adding the following to ‘a img’ CSS fixed it…

“vertical-align: bottom;”

---

<div class="post-metadata">

### Author: ![LilShieste](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@LilShieste](https://boards.straightdope.com/u/LilShieste)
#### Post date: [September 23, 2009, 11:02pm UTC](https://boards.straightdope.com/t/some-css-help-ie-8-strange-behaviour/511285/5 "2009-09-23T23:02:55Z")

</div>

> [@Lobsang](#):
>
> If I assign CSS to a link, it applies the same CSS to a linked image. I don’t know how to NOT do that.
> 
> How do I assign specific CSS to an image that would override the link CSS and stop the strange behaviour?

I think **Duckster** means to assign CSS to images/text separately, via the [“class” attribute](http://www.w3schools.com/Css/css_syntax.asp). You could designate a class value of “textLink” for any text hyperlinks to which you want to apply the CSS. Then, you would modify the CSS style as “a.textLink:hover”.

For example:

CSS

```auto

a.textLink:hover {background-color: #CCC;}

```

HTML

```auto

<a href="http://MyWebsite" class="textLink">Some text</a>
<a href="http://SomeOtherWebsite"><img src="http://MyWebsite/an_image.jpg" /></a>

```

---

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [September 23, 2009, 11:11pm UTC](https://boards.straightdope.com/t/some-css-help-ie-8-strange-behaviour/511285/6 "2009-09-23T23:11:38Z")

</div>

> [@LilShieste](#):
>
> I think **Duckster** means to assign CSS to images/text separately, via the [“class” attribute](http://www.w3schools.com/Css/css_syntax.asp). You could designate a class value of “textLink” for any text hyperlinks to which you want to apply the CSS. Then, you would modify the CSS style as “a.textLink:hover”.
> 
> For example:
> 
> CSS
> 
> ```auto
> 
> a.textLink:hover {background-color: #CCC;}
> 
> ```
> 
> HTML
> 
> ```auto
> 
> <a href="http://MyWebsite" class="textLink">Some text</a>
> <a href="http://SomeOtherWebsite"><img src="http://MyWebsite/an_image.jpg" /></a>
> 
> ```

Thanks for that. But I’d rather not have to create a class for it, because I want the hover behaviour for ALL the links on my website, so I don’t want to have to put class=“textlink” in every single one of them.

---

<div class="post-metadata">

### Author: ![Duckster](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/duckster/32/1244_2.png) [@Duckster](https://boards.straightdope.com/u/Duckster)
#### Post date: [September 24, 2009, 3:22am UTC](https://boards.straightdope.com/t/some-css-help-ie-8-strange-behaviour/511285/7 "2009-09-24T03:22:36Z")

</div>

> [@Lobsang](#):
>
> Thanks for that. But I’d rather not have to create a class for it, because I want the hover behaviour for ALL the links on my website, so I don’t want to have to put class=“textlink” in every single one of them.

Then reverse the logic. Apply a style that applies to all links that should have the same hover. Then create a special class for those that require something else.
