Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with IE when using display:block for links

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.

like image 306
Waleed Eissa Avatar asked May 19 '09 08:05

Waleed Eissa


4 Answers

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.

like image 136
Steven Wilber Avatar answered Nov 10 '22 15:11

Steven Wilber


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

like this

It will fix it :)

like image 6
vsync Avatar answered Nov 10 '22 14:11

vsync


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

like image 5
Mark Dickinson Avatar answered Nov 10 '22 14:11

Mark Dickinson


I have no idea why, but giving the anchor a background color seemed to fix this problem for me.

like image 5
Andrew Avatar answered Nov 10 '22 15:11

Andrew