Aligning <li> next to each other, not working
Asked Answered
H

4

12

I have a problem with aligment of two li elements inside a div because in the next example

HTML

<div id="menu-container">
    <div class="menu-left">
        <ul id="menu-principal" class="menu">
            <li><a href="">Hola</a></li>
            <li><a href="">Hola2</a></li>
        </ul>
    </div>
<!-- More code -->
</div>

The CSS code is in the next link and I use that html structure because that is what is generated by placing a menu in wordpress.

http://jsfiddle.net/Soldier/KhLhR/1/

I have a simple code with two li elements and I want to align horizontally with 50% of width for each but doesn't work.

Edit

Well.. All responses involve float: left, but did not want to use float: left because this causes overflow to ul and I have to use overflow: hidden .. I thought there was another factor that was failing but they all give +1 and accept the answer that answered first.

Thanks

Hammett answered 29/4, 2013 at 18:44 Comment(1)
@adaam Hi.. my original code uses inline-block too but to put my elements next to each other, I needed to place the float: left but didn't want to use that because I thought there was another way to do.Hammett
B
14

Add:

float: Left;

to the css class of the li elements of the menu (in this rule):

".menu-left ul li {"

After the "width: 50%"

The float property specifies whether or not a box (an element) should float. See http://www.w3schools.com/cssref/pr_class_float.asp

Barricade answered 29/4, 2013 at 18:48 Comment(1)
for rtl you should change this to float:right ( for rtl li ul menus)Ambrosia
I
12

This is purely to do with the fact that your width specification is more than you've allowed for the child element in relation to it's parent elements:

.menu-left ul li {
    display:inline-block;
    vertical-align: top;
    width: 50%; // should be less than 50%
}

Updated fiddle: http://jsfiddle.net/KhLhR/3/

Incuse answered 29/4, 2013 at 18:48 Comment(0)
V
4

http://jsfiddle.net/Soldier/KhLhR/1/

.menu-left ul li {
    display:inline-block;
    float:left;
    vertical-align: top;
    width: 50%;
}
Vindication answered 29/4, 2013 at 18:48 Comment(0)
A
4

Add a left float to your li elements:

.menu-left ul li {
    display:inline-block;
    vertical-align: top;
    width: 50%;
    float: left;
}
Andonis answered 29/4, 2013 at 18:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.