Martijn Verburg
Martijn Verburg

Reputation: 3305

DIV Layers interfering with links

I have some code as follows where I think my layering is causing a rendered link to be unclickable. Some of this example I've converted to styles from external CSS classes for ease of writing this up as a small use case. This is currently being testing on modern browsers (latest stable FF and Chrome).

<body>

<!-- whole container needs to be at z-index of -1 -->
<div id="container">

    <div class="corner" id="backgroundTopLeft"></div>
    <div class="corner" id="backgroundTopRight"></div>
    <div class="corner" id="backgroundBottomLeft"></div>
    <div class="corner" id="backgroundBottomRight"></div>

    <!-- whole container needs to be at z-index of 1 -->
    <div id="container2">

        <div id="headerSection"><img src="images/jClarity_logo.png" alt="logo" /></div>

        <div id="navigationSection">
            <a class="selected" href="#">Introduction</a><span class="menuDivider">|</span><a href="about.html">About</a>
        </div>

    </div>

</div> 
</body>

And the CSS

@charset "utf-8";

/* Default margin, padding and font-family */
*
{
    font-family: Arial;
    margin: 0px;
    padding: 0px;
}

/* All images should have no borders by default */
img
{
    border: none;
}

/* Global styling for links, uses black as the color */
a
{
    color: #000000;
    text-decoration: none;
}

a.selected
{
    font-weight: bold;
}

a:hover
{
    color:#FF00FF;
}

#container
{
    position: relative;
    z-index: -1;
    height: 100%;
}

.corner
{
    position: absolute;
    height: 100px;
    width: 100px;
    background-color: #172944;
    z-index: -1;
}

#backgroundTopLeft
{
    top: 0px;
    left: 0px;
}

#backgroundTopRight
{
    top: 0px;
    right: 0px;
}

#backgroundBottomLeft
{
    bottom: 0px;
    left: 0px;
}

#backgroundBottomRight
{
    bottom: 0px;
    right: 0px;    
}

#container2
{
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 1;
    opacity: 0.8;
    filter:alpha(opacity=80);
    background-image:url('../images/groovepaper.png');
}

/* The headerSection div, designed to fit in a centered logo */
#headerSection
{
    margin-left: auto;
    margin-right: auto;
    padding-bottom: 70px;
    padding-top: 54px;    
    height: 70px;
    width: 250px;
}

/* The navigationSection div, designed to fit in the menu */
#navigationSection
{
    padding-bottom: 15px;
    margin-left: auto;
    margin-right: auto;
    width: 600px;
    text-align: right;
}

.menuDivider
{
    color: #666666;
    padding-left: 5px;
    padding-right: 5px;
}    

It all looks fine (lots of other purely color/font-size type styling is applied), but foobar.html is not clickable.

I'm pretty sure I've done something wrong with the layering, but I thought the use of z-indices would sort me out..

Upvotes: 0

Views: 149

Answers (1)

Ashwin Singh
Ashwin Singh

Reputation: 7375

Working fine http://jsfiddle.net/hPkTu/, if the problem is with IE8, use z-index:1; IE8 is known to be buggy with this particular problem of z-index's.

UPDATE You changed your question, here is the working jsFiddle of your updated problem http://jsfiddle.net/VjTXu/2/. I changed z-index of container to O, -1 was making it go below body and that's why your link was not clickable, now it is.

Upvotes: 3

Related Questions