I am looking for a way to center an unordered list of unknown width without using a parent div wrapper, while still maintaining the left alignment of the list items.
Here is what I want to achieve:
HTML
<ul>
<li></li>
<li></li>
<li></li>
</ul>
CSS
ul { display: inline-block; text-align: left; }
The challenge here is that I do not have a fixed width for the <ul>
element. In this scenario, setting margin: 0 auto;
or text-align: center;
does not produce the desired result as it affects the alignment of the list items. Is there a way to center the <ul>
without using a parent div?
<ul>
<li></li>
<li></li>
<li></li>
</ul>
EDIT: To clarify, I need to achieve this without a <div>
wrapper. Are there any CSS tricks involving floats or pseudo elements that can help accomplish this?