views:

120

answers:

2

I've got a horizontal navigation bar made from an unordered list, and each list item has a lot of padding to make it look nice, but the only area that works as a link is the text itself. How can I enable the user to click anywhere in the list item to active the link?

html:

<html>
  <head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/test.css" />
    <link rel="shortcut icon" href="/images/favicon.ico" >
  </head>

  <body>
    <div id="nav">
    <img src="/images/renderedicon.png" alt="Icon" height="57" width="57"/>
      <ul>
        <li><a href="#">One1</a></li>
        <li><a href="#">Two</a></li>
        <li><a href="#">Three</a></li>
        <li><a href="#">Four</a></li>
      </ul>
    </div>
    <div>
      <h2>Heading</h2>
    </div>
  </body>
</html>

css:

#nav {
  background-color: #181818;
  margin: 0px;
  overflow: hidden;
}

#nav img {
  float: left;
  padding: 5px 10px;
  margin-top:auto;
  margin-bottom: auto;
  vertical-align: bottom;
}

#nav ul {
  list-style-type: none;
  margin: 0px;
  background-color: #181818;
  float: left;
}

#nav li {
  display: block;
  float: left; 
  padding: 25px 10px;
}

#nav li:hover {
  background-color: #785442;
}

#nav a {
  color: white;
  font-family: Helvetica, Arial, sans-serif;
  text-decoration: none;
}
+3  A: 

Don't put padding in the 'li' item. Instead set the anchor tag to display:inline-block; and apply padding to it.

Stussa
Not all versions of IE fully support `inline-block` (see http://www.quirksmode.org/css/display.html). Since `li` s are already floated, `a { display: block }` is probably the better choice.
dhabersack
`display: inline; zoom: 1;` in a conditional comment for IE6 and IE7 will replace `display: inline-block;` though yes, if list items are already floated, `display: block;` will be OK too
Felipe Alsacreations
+4  A: 

Make the anchor tag contain the padding rather than the li. This way, it will take up all the area.

Aaron Harun
I would also suggest moving the hover state to the anchor as well off of the li for better browser support.
NinjaBomb