Jonas Jonas - 8 months ago 66
CSS Question

Text-align without float for menubar with css

I'd like to have at the following menubar three items at the left side, the other one (eMail) on the right one.

ul.menubar {
list-style-type: none; /* entfernt Bulletpoints */
margin-left: 5px;
padding: 0px;
overflow-x: hidden;
background-color: #FFFFFF;
position: fixed;
width: 100%;
z-index: 1;
border-bottom: solid 1px #D4D4D4;

ul.menubar li {
float: left; /* Elemente sind linksbünding NEBENEINANDER angeordnet */
margin: 0px 10px 0px 10px;

#eMail {
position: right;
display: inline-block;
text-align: right;
float: right;

ul.menubar li a {
color: black;
display: inline-block;
text-align: center;
padding:15px; /* Innenabstand im Element bis zum Rand */
text-decoration: none; /* entfernt Unterstreichen der Elemente*/
transition: 0.3s; /* Animation zu :hover*/
font-family: Century Gothic;

<ul class="menubar" id=topmenubar>
<li><a href="#linkHome">Logo</a></li> <!-- bedeutet '#' gleicher Link + Ergänzung?-->
<li><a href="#linkContact">Contact</a></a></li>
<li><a href="#linkAbout">About</a></li>
<li><a href="#linkEmail" "id="eMail">eMail</a></li>

As I see float (and text-align/position as well) doesn't work. What can I do to move the eMail link to the right side?

Regards, Jonas

Answer Source

You can select the last element which is email with the nth-child() selector. And the following code place the email tab to the right of the menu.

li:nth-child(4) {
    float: right !important;