【问题标题】:How to horizontally center div? [duplicate]如何水平居中div? [复制]
【发布时间】:2018-02-01 21:07:02
【问题描述】:

<div style="width:100%; margin: 0 auto;">
    <div style="width:50%; background:#000">
        <p style="color:#fff">Text must be left.</p>
    </div>
</div>

请帮助我如何集中对齐子 div 和段落必须离开。请参考https://vsss.co.in/index.php/User?

【问题讨论】:

标签: css html


【解决方案1】:

您必须将margin:0 auto 添加到需要居中的元素。

<div style="width:100%; margin: 0 auto;">
    <div style="width:50%; margin:0 auto; background:#000">
        <p style="color:#fff">Text must be left.</p>
    </div>
</div>

【讨论】:

  • 嘿,你能看看vsss.co.in/index.php/User吗?
  • @SuthanBala,你看到vsss.co.in/index.php/User了吗?你的回答对 Bala.questioner 使用 margin: 0 auto 没有帮助。
  • @RushabhShah 抱歉刚刚看了,你想让我看哪里?顺便说一句,当您使用 margin:0 auto; 时,该元素还必须存在宽度。
  • @RushabhShah 如果你指的是.sign-in-page div,那个div 有100% 的宽度,所以你不会看到效果。如果您将宽度更改为较低的值,您会看到它居中
猜你喜欢
  • 2016-10-16
  • 2015-02-10
  • 2023-03-03
  • 2013-03-30
  • 2013-04-10
  • 2011-05-18
  • 1970-01-01
相关资源
最近更新 更多