css - A vertical Navigation bar with display:block on a link inside a <li> fill the entire width of the list item -


for vertical navigation nemu such 1 shown below,

            <ul id= "nav">                 <li>                     <a href = "#"> home</a>                 </li>                 <li>                     <a href = "#"> france</a>                 </li>                 <li>                     <a href = "#"> italy</a>                 </li>                 <li>                     <a href = "#"> spain</a>                 </li>                 <li>                     <a href = "#"> eastern mediterranean</a>                 </li>                 <li>                     <a href = "#"> islands</a>                 </li>             </ul> 

if put

#nav {          display: block;      } 

this makes link fill entire width of list item, turning clickable button. effect become obvious when add background color later.

before: enter image description here

after adding display:block property,

enter image description here

why same not achievable setting width : 100% on <a> inside <li>?

anchor element <a> inline element , doesn't adhere box model concept. element support width/height, padding/margin appropriately have force box model on , that's happens when use display:block;

read more box model: https://developer.mozilla.org/en-us/docs/web/css/box_model

when element turned block element css, automatically takes 100% width of parent.

few inline elements: span, a, small etc. block elements: div, p, li etc.

you can alter block elements behave inline adding css display:inline it.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -