Html 居中 <UL> + 保持 <LI> 对齐
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5347451/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Centering <UL> + Keeping <LI>'s Aligned
提问by CenterMe
My problem: http://i56.tinypic.com/ff3jmo.png
我的问题:http: //i56.tinypic.com/ff3jmo.png
The bullet points aren't aligned.
项目符号没有对齐。
All I'm going is text-align:center'ing the class in which the ul resides. Can I align the bullet points?
我要做的就是 text-align:center'ing ul 所在的类。我可以对齐项目符号吗?
EDIT: Hey guys, just want to try and clarify. I want the actual bullet points aligned. Currently the text is aligned, but not the bullet points.
编辑:嘿伙计们,只是想尝试澄清一下。我希望实际的项目符号点对齐。目前文本已对齐,但未对齐项目符号点。
- T e x t
- T e x t
- T e x t
- T e x t
- 文本
- 文本
- 文本
- 文本
Where as I want
随心所欲
- Text
- Text
- Text
- (Bullet points aligned, text centered)
- 文本
- 文本
- 文本
- (项目符号点对齐,文本居中)
回答by asthasr
text-align: center
isn't to be used for this purpose. You should probably put the <ul>
in a <div>
and center thatby setting it to a certain width and using margin-left: auto;
and margin-right: auto
.
text-align: center
不用于此目的。你或许应该把<ul>
一个<div>
和中心是将其设置为一定的宽度,并使用margin-left: auto;
和margin-right: auto
。
So:
所以:
<div style="width: 25%; margin-left: auto; margin-right: auto;">
<ul>
<li>List item 1</li>
<li>List item 2</li>
</ul>
</div>
回答by Hussein
You asked the question twice. I answered you at Centering Bullets On A Centered List
Give your div a class name center
. Assuming your div width is 200px, margin:0 auto
will center and text-align:left
will align the text to the left while maintaining its centering due to margin auto.
给你的 div 一个类名center
。假设您的 div 宽度为 200 像素,margin:0 auto
将居中并将text-align:left
文本向左对齐,同时由于边距自动保持居中。
.center{
width:200px;
margin:0 auto;
text-align:left;
}
Check working example at http://jsfiddle.net/8mHeh/1/
在http://jsfiddle.net/8mHeh/1/检查工作示例
回答by sharvari jadhav
You don't need margin just above the ul
tag add a div
and add style in it
text-align:left
您不需要在ul
标签上方添加边距div
并在其中添加样式
text-align:left
<div style="text-align:left">
<ul>
<li></li>
</ul>
</div>
回答by Simon M
Are you trying to get the li's to align to the left? If so, try putting all of the li's in the class "myliclass" and do this in CSS:
你是想让 li 向左对齐吗?如果是这样,请尝试将所有 li 放在“myliclass”类中,并在 CSS 中执行此操作:
.myliclass {
text-align:left;
}