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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:26:22  来源:igfitidea点击:

Centering <UL> + Keeping <LI>'s Aligned

htmlcss

提问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
  • 文本
    • 文本
      • 文本

Where as I want

随心所欲

  • Text
  • Text
  • Text
  • (Bullet points aligned, text centered)
  • 文本
  • 文本
  • 文本
  • (项目符号点对齐,文本居中)

回答by asthasr

text-align: centerisn'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 autowill center and text-align:leftwill 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 ultag add a divand 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;
}