Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List - Width is always 100%

Tags:

html

css

Basically I'm making some buttons but even through I put the width as auto and set padding, the list still extends 100% of the page. I don't want to set the width in pixels, I just want to set the padding either side.

Can anyone please explain where I have gone wrong: http://jsfiddle.net/spadez/KYdnJ/5/

#nav li { 
    color: #333; 
    line-height: 28px; 
    background-color: #F8F8F8; 
    border: 1px solid #D3D3D3; 
    padding: 0px 9px 0px 9px; 
    font-family: arial, sans-serif; 
    font-size: 11px; 
    width: auto;
}
like image 300
Jimmy Avatar asked Apr 19 '26 23:04

Jimmy


1 Answers

List items are similar to block-level elements in that their initial width value is equal to auto so by default they will span the width of their containing block if they aren't given a fixed size. You can either float or change the display value to inline-block; so that their width "shrinks to fit" its content, or you can just give the list-items a fixed width.

http://jsfiddle.net/KYdnJ/8/

like image 96
Adrift Avatar answered Apr 23 '26 17:04

Adrift



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!