As others have mentioned, you can set the li to display:inline; , or float the li left or right. Additionally, you can also use display:flex; on the ul . In the snippet below I also added justify-content:space-around to give it more spacing. For more information on flexbox, checkout this complete guide.
When you need to create a list that expands horizontally, you need to add the display:inline style to the <li> elements of the list. A horizontal list is commonly used for creating a website's navigation menu component.
The quickest way to display a list on a single line is to give the <li> elements a display property value of inline or inline-block . Doing so places all the <li> elements within a single line, with a single space between each list item.
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 (applying display: inline
to the overall list will have no effect):
#ul_top_hypers li {
display: inline;
}
Here is the working example:
#div_top_hypers {
background-color:#eeeeee;
display:inline;
}
#ul_top_hypers li{
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>
You could also set them to float to the right.
#ul_top_hypers li {
float: right;
}
This allows them to still be block level, but will appear on the same line.
Set the display
property to inline
for the list you want this to apply to. There's a good explanation of displaying lists on A List Apart.
As @alex said, you could float it right, but if you wanted to keep the markup the same, float it to the left!
#ul_top_hypers li {
float: left;
}
As others have mentioned, you can set the li
to display:inline;
, or float
the li
left or right. Additionally, you can also use display:flex;
on the ul
. In the snippet below I also added justify-content:space-around
to give it more spacing.
For more information on flexbox, checkout this complete guide.
#ul_top_hypers {
display: flex;
justify-content:space-around;
list-style-type:none;
}
<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>
It will work for you:
#ul_top_hypers li {
display: inline-block;
}
#ul_top_hypers li {
display: flex;
}
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