tags:

views:

25

answers:

4

I have a link inside a div that floats to the right of the screen. The link does not work in FF or Chrome, but works in IE (have only tested with IE8).

The simplest example looks like this:

<html>
<head>
<title>test</title>
<style type="text/css">
#logo {
 left:10px;
 float:left;
 top:10px;
} 
#feedback {
 float: right;
}
ul#menu
{
    position:relative;
}
ul#menu li
{
     display: inline;
     list-style: none;       
}
ul#menu li.last {
    margin-right: 50px;
}
</style>
</head>
<body>
<div class="page">
<div id="header">
    <div id="logo">logo</div>
    <div id="feedback"><a href="http://www.norge.no"&gt;test link</a></div>
    <div id="menucontainer"><ul id="menu"><li>test 1<li>test2</ul></div>
</div>
</div>

</body>

If i remove any of the float styles or position styles, the link becomes clickable in Chrome and Firefox. (but then my layout is off).

My question is: What's causing this, and is there a reliable way to solve it?

+1  A: 

I've had the same problem before. When you hover over the anchor, the cursor doesn't change to the pointer, and you can't click on the link.

Every time, it has been due to a positioned element that overlaps the anchor, effectively becoming a layer between the mouse and the anchor. Usually it is an image like you have.

Make sure that the image isn't so wide that it's boundary or css width property isn't overlapping the anchor. If that isn't the reason, do the same with the menucontainer.

Do you use firebug for firefox? If not, it might help discover any overlapping issues.

I have a question within an answer for you...why are you relatively positioning the ul#menu without declaring a top,bottom,left, or right attribute? Just curious. I'm not used to seeing those not there.

kevtrout
Thanks for a well explained answer. To answer your question: I believe the ul#menu li.last makes sure that the menu starts from the right and grows to the left. It appears that position:relative on the ul#menu is not necessary, and is probably left over from another attempt on right justifying the menu.
Per-Frode Pedersen
A: 

Put this to your styles


#menucontainer { clear: both; }
Ventus
A: 
ul#menu
{
    position:relative;
    overflow:auto;
}

appears to fix it.

I believe its because the floats aren't cleared, and you haven't specified any widths, so the two floated elements are "overlapping".

Ross
A: 

Try this

HTML

<html>
    <head>
    </head>
    <body>
        <div class="page">
            <div id="header">
                <div id="logo">logo</div>
                <div id="feedback"><a href="http://www.norge.no"&gt;test link</a></div>
                <br class="clear" />
                <div id="menucontainer">
                    <ul id="menu" class="clear">
                        <li>test 1</li>
                        <li>test2</li>
                    </ul>
                </div>
            </div>
        </div>
        ​</body>
</html>​​​​​​​​​​​​​​​​​​​​​​​

css

.clear{
    clear:both;
}
#logo {
    float:left;
    margin:10px;
} 

#feedback {
    float: right;
}

ul#menu
{
}
ul#menu li
{
    float:left;
}
ul#menu li a{
    display:block;
}
ul#menu li.last {
    margin-right: 50px;
}
​

working demo

JapanPro