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
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".
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With