Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal ul navigation aligned to the right side

i'm trying to create a horizontal navigation which is aligned to the right side of the parent element. You can see the navigation at http://kaffeeprinzen.jag-aelskar.de/ where it says "Espresso".

My HTML is:

<ul id="menu-standard">
    <li id="menu-item"><a>Item 4</a></li>
    <li id="menu-item"><a>Item 3</a></li>
    <li id="menu-item"><a>Item 2</a></li>
    <li id="menu-item"><a>Item 1</a></li>
</ul>

My CSS is:

.menu li { 
    float: right;
    margin-left: 20px;
}

It works like this, the only problem is that the order in the list is wrong. The first item is the last one in the html code.

Any tips for me? Thanks a lot! Yannis

like image 870
user731101 Avatar asked Jul 13 '11 18:07

user731101


People also ask

How do I align ul items to the right?

To make a right-aligned version of the list, only three changes need to occur. First, set the "UL" "text-align" to "right". Second, change the left "background-position" from "0" to "100%" - which makes the image align up with the right edge. And finally change "padding-left" to "padding-right".

How do you display ul elements horizontally?

If you want to make this navigational unordered list horizontal, you have basically two options: Make the list items inline instead of the default block. .li { display: inline; } This will not force breaks after the list items and they will line up horizontally as far as they are able. Float the list items.

How do I align a tag to the right?

To set text alignment in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property text-align for the center, left and right alignment.


1 Answers

Try floating the ul right rather than each li. Each li can float left.

#menu-standard { 
    float: right;
}

#menu-standard li { 
    float: left;
}

Example: http://jsfiddle.net/hunter/HsUTQ/


float: right will float the items, in order, to the right. Meaning the 1st element will be the right-most, then 2nd element the next-right-most, etc.

like image 78
hunter Avatar answered Oct 30 '22 11:10

hunter