Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why menu created with ul li elements displayed in reverse order?

Tags:

html

css

I have created a menu using ul and li, but it shows me in reverse order. For example:

FAQ PRICING TOUR HOME instead of the expected HOME TOUR PRICING FAQ

.header ul {

}
.header li {
   list-style-type: none;
   margin-left: 40px;
   float: right;
}

<div class="header">
   <ul>
      <li><a href="">HOME</a></li>
      <li><a href="">TOUR</a></li>
      <li><a href="">PRICING</a></li>
      <li><a href="">FAQ</a></li>
   </ul>
</div>

What's wrong in my code?

like image 642
snehal Avatar asked May 19 '14 12:05

snehal


People also ask

Why is my nav bar backwards?

This is happening because that's how float was designed. It will "float" the elements in the direction specified, in the order specified.

Why do we put links in a list using UL and Li?

You should be using an unordered list of items ( UL element with LI elements) to be semantically correct about it. This also helps screen readers and other technologies that depend on correct semantics to work.


1 Answers

You should float only the ul right. The list items should be floated left in the correct (expected) order:

.header ul {
    float:right;
}

// expected order. It's the default value if not overriden,
// therefore it is not realy needed
.header li
{
    float:left;
}
like image 146
Christian Gollhardt Avatar answered Sep 21 '22 17:09

Christian Gollhardt