Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS list item width/height does not work

Tags:

css

I tried to make a navigation inline list. You can find it here: http://www.luukratief-design.nl/dump/parallax/para.html

For some reason it does not display the width and height of the LI. Here is the snippet. What is wrong with this?

.navcontainer-top li {     font-family: "Verdana", sans-serif;     margin: 0;     padding: 0;     font-size: 1em;     text-align: center;     display: inline;     list-style-type: none;<br>     width: 117px;     height: 26px; }   .navcontainer-top li a {     background: url("../images/nav-button.png") no-repeat;     color: #FFFFFF;     text-decoration: none;     width: 117px;     height: 26px;     margin-left: 2px;     margin-right: 2px; } .navcontainer-top li a:hover {     background: url("../images/nav-button-hover.png") no-repeat;     color: #dedede; } 
like image 620
Luuk Avatar asked Feb 19 '10 09:02

Luuk


People also ask

Why height and width is not working in CSS?

By changing the display property from inline to block or inline-block , height and width should be worked properly.

How do I change the width of a Li in HTML?

You'd have to work on your code because you can't assign widths to inline elements. But this can be solved by setting the display to block and by floating it.


2 Answers

Declare the a element as display: inline-block and drop the width and height from the li element.

Alternatively, apply a float: left to the li element and use display: block on the a element. This is a bit more cross browser compatible, as display: inline-block is not supported in Firefox <= 2 for example.

The first method allows you to have a dynamically centered list if you give the ul element a width of 100% (so that it spans from left to right edge) and then apply text-align: center.

Use line-height to control the text's Y-position inside the element.

like image 69
Tatu Ulmanen Avatar answered Sep 30 '22 14:09

Tatu Ulmanen


Inline items cannot have a width. You have to use display: block or display:inline-block, but the latter is not supported everywhere.

like image 36
Ikke Avatar answered Sep 30 '22 13:09

Ikke