How to center an unordered list?
ul {
display: table;
margin: 0 auto;
}
<html>
<body>
<ul>
<li>56456456</li>
<li>4564564564564649999999999999999999999999999996</li>
<li>45645</li>
</ul>
</body>
</html>
Let's say the list is:
<ul>
<li>item1</li>
<li>item2</li>
<li>item3</li>
</ul>
For this example. If I understand correctly, you want the list items to be in the middle of the screen, but you want the text IN those list items to be centered to the left of the list item itself. Doing that is actually pretty easy. You just need some CSS:
ul {
display: table;
margin: 0 auto;
text-align: left;
}
And it works! Here is what is happening. First, we say we want to affect only unordered lists. Then, we do Rafael Herscovici's trick for centering the list items. Finally, we say to align the text to the left of the list items.
To center align an unordered list, you need to use the CSS text align property. In addition to this, you also need to put the unordered list inside the div element.
Now, add the style to the div class and use the text-align property with center as its value.
See the below example.
<style>
.myDivElement{
text-align:center;
}
.myDivElement ul li{
display:inline;
}
</style>
<div class="myDivElement">
<ul>
<li>Home</li>
<li>About</li>
<li>Gallery</li>
<li>Contact</li>
</ul>
</div>
Here is the reference website Center Align Unordered List
list-style-position:inside
Use list-style-position:inside
:
ul {
text-align: center;
list-style-position: inside;
}
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>