Link Inside <li> No Working

9.7k views Asked by At

Pretty simple nut I'm trying to crack. I'm doing image rollovers with CSS only. When I plugged in my a href link, it just does not work. By not work I mean, it does not act like it's a link and as a result you cannon click through to the page. Figuring it has something to do with the <li> but I can't figure out what. Here's my HTML and CSS:

CSS

    ul.navigation,
    ul.navigation ul {
    margin: 25px 0 0 0;
    }
    ul.navigation li {
    list-style-type: none;
    margin:15px;
  }

.AboutUsNav{
    display: block;
    width: 159px;
    height: 54px;
    background: url('../images/N_About_Us.png') bottom;
    text-indent: -99999px;
}
.AboutUsNav:hover {
    background-position: 0 0;
}

HTML

<div>
<ul class="navigation">
<li class="AboutUsNav"><a href="/about">About Phin &amp Phebes Ice Cream</a></li>
<li class="FlavorsNav"><a href="/flavors">Ice Cream Flavors</a></li>
<li class="WheretoBuyNav"><a href="/buy">Where to Buy Our Ice Cream</a></li>
<li class="WholesaleNav"><a href="/wholesale">Wholesale Orders Ice Cream</a></li>
<li class="ContactUsNav"><a href="/contact">Contact Phin &amp; Phebes Ice Cream</a></li>
<li><a href="http://phinandphebes.com/about">about</a></li>

</ul>
</div>
3

There are 3 answers

0
alex On

Your .AboutUsNav has text-indent: -99999px;, pulling the a outside of the clickable viewport.

You probably want to put the negative text-indent on the a itself, and then set the a element to display: block; width: 100%; height: 100%, depending on your circumstances.

0
Samuel Liew On

don't apply the text-indent and background to the list - do it to the link instead.

Example:

<div id=​"main_nav">
    <li class="home">
        <a href="/">Home</a>
    </li>
    <li class="news">
        <a href="/">News</a>
    </li>
</div>

CSS:

#main_nav a {
    background-image:url();
}
#main_nav .home a {
    width: 82px;
    background-position: 0px 0px;
}
#main_nav .news a {
    width: 85px;
    background-position: 82px 0px;
}
0
Jess Eddy On

thank you for your help. I tried the approach you both recommended. I think this definitely works under certain circumstances. For me, my background image just wasn't showing up but the links were working.

I ended up solving this problem by leaving the CSS the same but changing the HTML markup as so:

<div>
<ul class="navigation">
    <li><a class="AboutUsNav" href="/about">About Phin &amp; Phebes Ice Cream</a></li>
    <li><a class="FlavorsNav" href="/flavors">Phin &amp; Phebes Flavors</a></li>
    <li><a class="WheretoBuyNav" href="/buy">Where to Buy Phin &amp; Phebes Ice Cream</a></li>
    <li><a class="WholesaleNav" href="/wholesale">Wholesale Orders Ice Creamf</a></li>
    <li><a class="ContactUsNav" href="/contact">Contact Phin &amp; Phebes Ice Cream</a></li>
</ul>

I was working off this demo, which didn't include an unordered list: http://kyleschaeffer.com/best-practices/pure-css-image-hover/