Learn how to center a list with CSS.
Wrap the <ul>
element inside a container element, like <div>
:
<div class="container">
<ul class="myUL">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
</div>
Center-align the <div>
element, and change the display of <ul>
to inline-block
.
Optionally, you can left-align the list items for a more tidy view:
div.container {
text-align: center;
}
ul.myUL {
display: inline-block;
text-align: left;
}
Try it Yourself »
Tip: Go to our CSS Align Tutorial to learn more about aligning elements.
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!