views:

106

answers:

3

I have the following HTML:

<!DOCTYPE html>
<html>
    <head>
        <style>
            #nav {
                float: left;
                width: 10em;
            }

            #nav ul {
                list-style: none;
                margin: 0;
                padding: 0 20px;
            }

            #nav li {
                margin-top: 9pt;
                position: relative;
            }

            #nav a {
                border: solid 1px black;
                display: block;
                width: 10em;
                padding: 3px 0;
            }
        </style>
    </head>
    <body>
        <div id="container1">
        <div id="container2">
            <div id="nav">
                <ul>
                    <li><a href=".">Welcome</a></li>
                    <li><a href="news">News</a></li>
                    <li><a href="#">About</a>
                        <ul>
                            <li><a href="faq">FAQ</a></li>
                            <li><a href="charity">Charity</a></li>
                            <li><a href="committee">Committee</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
           <div id="section">If this p is here, the block links no longer work.<br><br><br></div>
       </div>
       </div>
       </div>
    </body>
</html>

In IE8 the text in #section prevents the whitespace in a block link from being a link. While there is text to the right, the whitespace in the links breaks. When the #section div ends, the links work fine and the whole thing is a link rather than just the text.

How would I make the whole a element a link all the time, rather than just the text when the #section div interfers? I've tried z-order to no avail.

A: 

Either remove the width: 10em; in your #nav style, or change it to width: 210px;.

Gert G
A: 

After trying out your code, I've found that the links work just fine for me with your code as it's posted above; I only ran your problem when the #section div was relatively positioned. In that case, #section gets placed higher than the links and actually covers them. That's why it looks as if the link simply doesn't work. Put a background color on #section and you'll see what I mean.

You actually can fix it using the z-index property. Set it to a value of about 10 for #nav li and use any number higher than that for #section, and as long as both of those elements are relatively positioned, you should see the links on top of the #section div. It should look something like this:

#nav li { margin-top: 9pt; position: relative; z-index: 10; }

#section { position: relative; z-index: 20; }

For more on positioning, there's a really good article at CSS-Tricks that you might want to read: http://css-tricks.com/absolute-relative-fixed-positioining-how-do-they-differ/

derekerdmann
`z-index` won't solve the issue (ICR mentions that he had tried it to no avail... and I tried it as well). Replace his *section* `DIV` with `<div id="section">If this p is here, the block links no longer work.<br>If this p is here, the block links no longer work.</div>` and try to click the *Welcome* box where the text in the *section* `DIV` overlaps the *Welcome* box. It selects text from the *section* `DIV` instead of firing on the *Welcome* link.
Gert G
Right. z-index only works when both elements have been positioned. a `position:relative` needs to be added to `#section` to make a difference.
derekerdmann
A: 

The solution was to add a background color to #nav

ICR
How did that solve the problem? Did you just get to see what was going on with the elements' positioning?
derekerdmann
Changing the background color triggered the hasLayout() method within IE which wasn't previously triggered. If this actually fixed it, please mark your answer as correct.
David