views:

742

answers:

3

This is my HTML:

<div id="links">
  <a href="">Link 1</a>
  <a href="">Link 2</a>
  <a href="">Link 3</a>
  <a href="">Link 4</a>
</div>

And these are the CSS styles:

#links {
    position: absolute;
    border: 1px solid #000;
}

#links a {
    display: block;
}

#links a:hover {
    background-color: #CCC;
}

This displays a list of links, the problem is that in IE, I can only click a link by directly clicking the text link, which is not the case with other browsers (where you can click anywhere whether the text link or anywhere else as long as it's in the link block), is there any fix for that (with only CSS, no javascript)?

Please note that I don't want to specify a width for the links or the div.

+3  A: 

Enclose the link text in a span element. Then it will accept clicks anywhere within it's bounds.

Mark Dickinson
Thanks a lot, that worked.
Waleed Eissa
This solutions is less semantic than just adding position:relative
vsync
+1  A: 

Put position:relative; in your CSS at #links a{ }

like this

It will fix it :)

vsync
A: 

I have had the same problem and none of the solutions above worked for me. I also needed the background of the links to be transparent. A very uncomfortable solution, but one that worked perfectly is to set the background to a transparent gif. Only needs to be 1x1 px as it will repeat.

links a

{ display: block; background: url(/images/interface/blank/1dot.gif); }

This seems to have no side effects apart from one additional request to the server.

Steven Wilber