My navigation list is overlapping padding. How can I prevent this?
css, html-lists, overlap, padding
Solution
Since you're using `padding` property on your anchor tags to increase their width, it doesn't need to specify `width: 100%`. Just remove that, and it works:
#menubar ul li a {
text-decoration:none;
color:#005da4;
display:block; /* Since li element is floated itself */
/* it doesn't need to use inline-block value for display */
/* width:100%; */ /* <-- remove this declaration */
padding: 10px 20px;
text-align:center;
margin-left:0;
margin-right:0;
}
Edited Fiddle.
Problem
I am trying to make a navigation that highlights the area around the link when you hover over it, and allows you to click on the any area of the highlight to follow that link. It seems that my padding is overlapping and you can only click on the padding to the left of the link, whereas the padding on the right becomes the left padding of the link the the right. JSFiddle: http://jsfiddle.net/Hh7XG/1/ HTML ``` <div id="menubar"> <ul> <li><a href=# >Home</a></li> <li><a href=# >About Us</a></li> <li><a href=# >Online Courses</a></li> <li><a href=# >Registration</a></li> <li><a href=# >Faculty</a></li> <li><a href=# >Calendar</a></li> <li><a href=# >Store</a></li> <li><a href=# >Testimonials</a></li> <li><a href=# >Online Lectures</a></li> <li><a href=# >Contact Us</a></li> <li><a href=# >Forum</a></li> <li><input class="searchbox" trype="text" value="Search" onfocus="this.value='';" onblur="if(this.value=='') this.value='Search';"/> </li> </ul> <div style="clear:both;"></div> </div> ``` CSS ``` #menubar{ height:auto; background:#ebebec; margin-top:0px; padding-top:0px; padding-left:0px; } ul{ list-style-type:none; padding:0px; margin:0px; } #menubar ul li{ text-decoration:none; color:#005da4; text-align:center; margin:none; width:auto; padding-left:0; padding-right:0; float:left; } #menubar ul li:hover a{ background:#acce39; } #menubar ul li a{ text-decoration:none; color:#005da4; display:block; width:100%; padding-left:20px; padding-right:20px; padding-top:10px; padding-bottom:10px; text-align:center; margin-left:0; margin-right:0; } .searchbox { -moz-border-radius: 15px; border-radius: 15px; border:solid 1px black; padding:5px; margin:5px; margin-left:15px; align:left; } ``` (Sorry if the below does not make sense. I would be more than happy to clarify.) I want it to display like this: (| is the border between li's) ``` | Link | Link | Link | ``` When I hover over the padding to the right of the leftmost link, I would like it to look like this: (X is the highlight, ^ is my mouse) ``` |XXXXLinkXXXX| Link | Link ^ ``` but it is acting like this: ``` | Link| Link| Link | ``` When the mouse is hovering over the leftmost link the highlight looks like this: ``` |XXXXLinkXXXX|Link | Link ^ ``` but when I hover over the padding to the right of of the link it looks like this: ``` | Link|XXXXLinkXXXX|Link | ^ ```