I have the following markup,
#menu li { padding: 0px; }
#menu li a { margin: 0px; display: block; width: 100%; height: 100%; }
It may need some tweaking for IE6, but that's about how you do it.
Use jQuery so you don't have to write inline javascript on <li>
element:
$(document).ready(function(){
$("li > a").each(function(index, value) {
var link = $(this).attr("href");
$(this).parent().bind("click", function() {
location.href = link;
});
});
});
Anchor href link apply to li:
#menu li a {
display:block;
}
As Marineio said, you could use the onclick
attribute of the <li>
to change location.href
, through javascript:
<li onclick="location.href='http://example';"> ... </li>
Alternatively, you could remove any margins or padding in the <li>
, and add a large padding to the left side of the <a>
to avoid text going over the bullet.
How to make the HTML link activated by clicking on the <li> ?
By making your link as big as your li: just move the instruction
display: block;
from li to a and you are done.
That is:
#menu li
{
/* no more display:block; on list item */
list-style: none;
background: #e8eef4 url(arrow.gif) 2% 50% no-repeat;
border: 1px solid #b2b2b2;
padding: 0;
margin-top: 5px;
}
#menu li a
{
display:block; /* moved to link */
font-weight: bold;
text-decoration: none;
line-height: 2.8em;
padding-right:.5em;
color: #696969;
}
Side note: you can remove "ul" from your two selectors: #menu is a sufficient indication except if you need to give weight to these two rules in order to override other instructions.
This will make whole <li>
object as a link :
<li onclick="location.href='page.html';" style="cursor:pointer;">...</li>