views:

514

answers:

4

hi

How can I vertically align items in an unordered list to work also in IE6,7? I can't just set line-height to the full height because I have both 1 row items and 2 rows items

My html code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"&gt;
<html>
    <head>
        <title></title>
        <style type="text/css">
            ul {
                list-style: none;
                border: 1px solid black;
                height: 40px;
            }
            li {
                float: left;
                margin-right: 10px;
                height: 40px;
                width: 46px;
            }
            a {

            }
        </style>
    </head>
    <body>
        <ul>
            <li>
                <a href="/">item1</a>
            </li>
            <li>
                <a href="/">two lines</a>
            </li>
        </ul> 
    </body>
</html>

Thanks

A: 

You cannot float your items to the left and expect them to vertically line up....

Remove

float: left;

From the LI style...

nwhiting
I need all items to be of the same width.That's why I'm using float instead of display:inline.Items with two words should take two rows.Is it possible to achieve this without float?
pablo
Yes, you can... you need to remove the width limitation for the listed items set it to simply auto or 100%.
nwhiting
using width:auto will make all items appear in one line.I want all the items to have the same width.Items with long text should span two rows.
pablo
You first need to remove the float: left; and replace with with clear: both; or display: block; ... edit ...I misunderstood what exactly you were attempting ... To separate the "words" by a "space" cannot be done dynamically within CSS, you would need to perform this action using javascript. In which it will explode words seperated by a "space" and break them into seperate listed items.
nwhiting
using float and width I can make the word split to two rows.
pablo
I believe this is a bit of confusion here, let me try and clarify a few things. You are attempting to horizontally display listed items, where a item with "two or more" words are broken down vertically. Using a left float and width it is perfectly possible, but not recommended as once you begin to tile these listed items IE will not play very nicely with a lists that have uneven heights and float ... You may either 1) Set a height large enough to accommodate the amount of words you expect. 2) Use javascript to adjust the lists accordingly.
nwhiting
A: 

Sorry if this isn't a proper answer, but it may help clear things up:

Why are you using floats instead of display: inline for your list items?

Anthony
A: 

The rows essentially be the same height. So there is no way to effectively "merge cells" in table speak. You should set the line height to the height of the "two line" items and then use the vertical-align property to align them.

prodigitalson
A: 

This link should be of some help.

ryanulit
doesn't help. thanks
pablo
I guess you are not trying to make a vertical menu then :).
ryanulit