How can I make my list items appear horizontally in a row using CSS?
#div_top_hypers {
background-color:#eeeeee;
display:inline;
}
#ul_top_hypers {
display: inline;
}
<div id="div_top_hypers">
<ul id="ul_top_hypers">
<li>‣ <a href="" class="a_top_hypers"> Inbox</a></li>
<li>‣ <a href="" class="a_top_hypers"> Compose</a></li>
<li>‣ <a href="" class="a_top_hypers"> Reports</a></li>
<li>‣ <a href="" class="a_top_hypers"> Preferences</a></li>
<li>‣ <a href="" class="a_top_hypers"> logout</a></li>
</ul>
</div>
Set the
display
property toinline
for the list you want this to apply to. There's a good explanation of displaying lists on A List Apart.It will work for you:
As others have mentioned, you can set the
li
todisplay:inline;
, orfloat
theli
left or right. Additionally, you can also usedisplay:flex;
on theul
. In the snippet below I also addedjustify-content:space-around
to give it more spacing.For more information on flexbox, checkout this complete guide.
List items are normally block elements. Turn them into inline elements via the
display
property.In the code you gave, you need to use a context selector to make the
display: inline
property apply to the list items, instead of the list itself (applyingdisplay: inline
to the overall list will have no effect):Here is the working example:
As @alex said, you could float it right, but if you wanted to keep the markup the same, float it to the left!