How to put HTML elements in a line?

Viewed 70

I've got this code...

        <div class="header">
            <div class="mainh">

                <div class="table">

                    <ul>
                        <li><a>smth</a></li>
                        <li><a>smth</a></li>
                        <li><a>smth</a></li>
                        <li><a>smth</a></li>
                        <li><a>smth</a></li>
                    </ul>
                </div>

            </div>          
        </div>

And what I want is to put the ul, li and a in a single line with the same distance between them.
How do I make it?

BTW I tried something. What I tried:

div.table ul li a {
    display: block;
}

...but it doesn't change the alignment.

5 Answers

Try this:

ul li { float: left; margin-right:30px; }
<div class="header">
  <div class="mainh">
    <div class="table">
      <ul>
        <li><a>smth</a></li>
        <li><a>smth</a></li>
        <li><a>smth</a></li>
        <li><a>smth</a></li>
        <li><a>smth</a></li>
      </ul>
    </div>
  </div>          
</div>

li {
  display: inline;
}
        <div class="header">
            <div class="mainh">

                <div class="table">

                    <ul>
                        <li><a>smth</a></li>
                        <li><a>smth</a></li>
                        <li><a>smth</a></li>
                        <li><a>smth</a></li>
                        <li><a>smth</a></li>
                    </ul>
                </div>

            </div>          
        </div>

Change your display to inline instead of block. block would make it list in multiple lines. Inline would make it look like a header menu in one line

try this :

.ul {
display: flex;
justify-content: space-evenly;
}

ul li 
{
   float: left; /* To make it in a single line */
   margin-right: 50px; /* Distance */
   margin-left: 50px; /* Distance */
}

Related