I know this has been up a lot of times before, but I couldn\'t find any solution in my specific case.
I\'ve got a navigation bar and I want the whole
<div>
s. <a>
tags to have display: block
<li>
to the <a>
. <li>
s will need to be either floated or display: inline-block
Example: http://jsfiddle.net/8yQ57/
I myself just had this problem.
The answer couldn't be simpler:
<li class="menuitem"><a href="index.php"><div class="menulink">Lnk1</div></a></li>
Wrong:
.menuitem {
list-style-type: none;
display: inline;
margin-left: 5px;
margin-right: 5px;
font-family: Georgia;
font-size: 11px;
background-color: #c0dbf1;
border: 1px solid black;
padding: 10px 20px 10px 20px;
}
Correct
.menuitem a {
list-style-type: none;
display: block;
margin-left: 5px;
margin-right: 5px;
font-family: Georgia;
font-size: 11px;
background-color: #c0dbf1;
border: 1px solid black;
padding: 10px 20px 10px 20px;
}
in other words, you want to apply the css that the LI's had to the A element. Making sure that the A is a block line element
a sir you use jquery ? if yes, you can try it :
$("li").click(function(){
$(this).find('a').click();
});
or you could use it too as css:
li{
position:relative;
}
li a {
position:absolute;top:0px;left:0px;width:100%;height:100%;
}
Choose one ... Good luck
You should make the a
elements display:block
or display:inline-block
.
Move the <a>
tags so that they wrap the <li>
tags. According to this answer, anchor tags must contain inline elements, and it looks like your <li>
's are inline, so this should be valid.
Just use "display block" for link.
ul {
display: block;
list-style-type: none;
}
li {
display: inline-block; /* or block with float left */
/* margin HERE! */
}
li a {
display: block;
/* padding and border HERE! */
}
Here's the example http://jsfiddle.net/TWFwA/ :)