How can I positioning LI elements to the bottom of UL list
Asked Answered
N

3

10

I have menu items like: Row1 Row2.. RowN and I want them not to be that wide - that's why including breaks (with max-width)

I have this HTML:

<div>
 <ul>
  <li>Row1</li>
  <li>Row1 Row2 Row3</li>
  <li>Row1</li>
  <li>Row1 Row 2</li>
 </ul>
</div>

with this CSS:

/* MENU */

.menudiv {padding-left:10px; border-bottom: 1px solid #d0db88;}

ul.menu
{                 
    list-style-type: none;
    min-width: 1050px;
    position: relative;
    left:10px;
    display: block;
    height: 45px;       
    margin: 0;
    padding: 0;
}

ul.menu li
{    
    float: left;
    margin: 0;
    padding: 0;
}

ul.menu li a
{    
    float: left;    
    text-decoration: none;
    padding: 9px 12px 0;
    font-weight: bold;
    max-width:130px;
}

Actual:

+--------------------+
|Row1 Row1 Row1 Row1 |
|     Row2      Row2 |
|     Row3           |
+--------------------+

What I need:

+--------------------+
|     Row1           |
|     Row2      Row1 |
|Row1 Row3 Row1 Row2 |
+--------------------+
Norland answered 22/12, 2010 at 14:55 Comment(3)
This may or may not be a question better suited for Doctype.com.Fetching
How can I migrate it to the other forum?Norland
The following question deals with migrating questions, but it seems you cannot do it yourself immediately. meta.stackexchange.com/questions/10249/…Fetching
T
4

Use display: inline-block instead of float:

ul.menu
{                 
   vertical-align: bottom;
}

ul.menu li
{    
   display: inline-block;
   text-align: center;
}

EDIT: Added text-align: center;. If I understand your comment correctly, that is what you want. If not, you'll need to be more specific.

Talbot answered 22/12, 2010 at 15:14 Comment(1)
I've got this problem yet: If the menu item is Word & LongWord, the second one will be aligned left (LongWord) and I need to have them both centered..Norland
M
0

http://css-tricks.com/what-is-vertical-align/ This link might help, alternatively you could create the result as table based content with the content aligned to the bottom of each cell.

Mev answered 22/12, 2010 at 15:7 Comment(0)
D
0

Assuming that following is your html

<div>
    <ul>
        <li><a>Row1</a></li>
        <li><a>Row1 Row2 Row3</a></li>
        <li><a>Row1</a></li>
        <li><a>Row1 Row 2</a></li>
    </ul>
</div>

You can simply style your CSS as following

li {
    position:relative;
    float:left;       
}

li a {
    position:absolute;
    bottom:0;
}

Above code should work across browsers (I have not tested this across browsers)

Doura answered 3/8, 2015 at 23:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.