0

I have create a navigation menu but the problem i face is that when i hover my mouse to the edge each menu block the ancor tag does not work, it works only when i place the mouse near the text. my question is that i want to make the whole block clickable any solutions?

Here a fiddle.

The markup.

<div id="nav">
    <ul class="menu">
        <li><a href="index.html">Home</a></li>
        <li><a href="about.html">About</a></li>
        <li><a href="/work/">Products</a></li>
        <li><a href="/contact/">Careers</a></li>
        <li><a href="/contact/">Contact</a></li>
    </ul>
</div>

The CSS.

#nav {
    width: 960px;
    background: #222222;
}

.menu {
    width: 960px; 
    margin: auto;
    padding: 0;
list-style: none;
text-align: center;
}

.menu li {
    display: block;
    border-right: 5px solid #222222;
    border-bottom: 3px solid #222222;
    padding: 10px;
    float: left; 
    width: 166px;
    height: 20px;
    font-family: 'Open Sans', sans-serif;
    font-size: 14px;
    background: #0C5E91;
}

.menu li:hover {
    background: #95d629;
}

.menu li a {
    display: block;
    float: left;
    width: 140px;
    height: 20px;
    font-family: 'Open Sans', sans-serif;
    font-size: 14px;
}

.menu li a { 
    text-decoration: none;
    color: white;
}
Octavian Helm
  • 39,405
  • 19
  • 98
  • 102
Shahil M
  • 3,836
  • 4
  • 25
  • 44
  • Possible duplicate of: http://stackoverflow.com/questions/3074454/how-do-i-make-the-whole-area-of-a-list-item-in-my-navigation-bar-clickable-as-a?rq=1 – James Bruckner Sep 15 '13 at 18:42

3 Answers3

3

Add width, height, and padding to the </a> element, not the <li>.

http://jsfiddle.net/tv8Dw/2/

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
0
$('#nav').click(function(){  alert('clicked'); });
Pratik
  • 1,550
  • 1
  • 9
  • 9
0

Put the <a href> before <li> :) and close </a> after </li>

EloiseM
  • 39
  • 1
  • 10