【问题标题】:Centering div element居中 div 元素
【发布时间】:2021-01-20 23:23:36
【问题描述】:

如何在主块中居中描述描述? 我尝试使用{margin: auto}{margin-left:auto, margin-right:auto},但没有帮助。

<main class="row">
  <div class="description">A little description</div>
</main>

【问题讨论】:

标签: html centering


【解决方案1】:

这应该可以帮助你:

.description {
display: flex;
align-items: center;
justify-content:    
}

【讨论】:

  • justify-content 需要某种值,这是一个错误吗?
【解决方案2】:

你需要告诉 description-

是 inline-block ,否则它会留在那里。在您的样式表中尝试以下条目:
.description {
  display: inline-block;
  text-align: center;
}

【讨论】:

    【解决方案3】:

    如果您使用的是 Bootstrap 4,请使用 mx auto。

    <head>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
        </head>
        <body>
    <main class="row">
      <div class="description mx-auto">A little description</div>
    </main>
    </body>

    否则

    .description {
      text-align:center;
    }
     <main class="row">
          <div class="description">A little description</div>
        </main>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-24
      • 2012-11-15
      • 2015-02-06
      • 2015-11-23
      • 2021-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多