html5 - background-color property not taking up entire li -


i have html5 code:

<div id = 'nav'>     <ul>         <a href = ''>             <li>home</li>         </a>         <a href = ''>             <li class = 'final_nav'>faq</li>         </a>     </ul> </div> 

and css stylesheet:

#nav {     border: 1px solid #000;     padding: 5px;     background-color: #e5e5e5; } #nav li {     border-left: 1px solid #000;     padding: 22px;     display: inline; } #nav li:hover{     background-color: #a9a9a9; } .final_nav {     border-right: 1px solid #000; } #nav {     display: inline-block; } #nav a:hover {     text-decoration: none; } 

but when hover on nav li, the background-color: #a9a9a9 property doesn't work to: enter image description here

how alter css dark-grey background take whole li not borders?
thanks

edit:

sorry, realised code works when alone, when include parent div, code produces error above. here whole header code:

html:

<div id = 'header'>     <h1>contest coding</h1>     <p>the free programming competition everyone</p>     <div id = 'nav'>         <ul>             <a href = ''>                 <li>home</li>             </a>             <a href = ''>                 <li class = 'final_nav'>faq</li>             </a>         </ul>     </div> </div> 

css:

body {     margin: auto;     width: 960px;     font-family: helvetica, sans-serif;     font-size: 16px; } #header {     text-align: center; } #nav {     border: 1px solid #000;     padding: 5px;     background-color: #e5e5e5; } #nav li {     border-left: 1px solid #000;     padding: 22px;     display: inline; } #nav li:hover{     background-color: #a9a9a9; } .final_nav {     border-right: 1px solid #000; } #nav a:hover {     text-decoration: none; } 

can me background-color problem?

as far know, wrapping <li> elements in ancor tags not best way this. it's other way around. if switch over, css works fine.

<div id = 'nav'>     <ul>         <li>             <a href = ''>home</a>         </li>         <li class="final_nav">             <a href = ''>faq</a>         </li>     </ul> </div> 

jsfiddle


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -