【问题标题】:Aligning <div> in vertically center [duplicate]垂直居中对齐 <div> [重复]
【发布时间】:2018-10-29 00:50:52
【问题描述】:

我无法垂直对齐#container 及其在中心的内容。我认为添加更多的&lt;div&gt; 标签会有问题,我无法控制它们。

我希望文本和#container.content 的中心垂直对齐,而不添加任何额外的空间。

#container {
  display: grid;
  padding: 20px;
  grid-template-areas: 'sideone sideone sidetwo sidetwo sidethree sidethree';
  grid-gap: 20px;
  text-align: center;
}

.content {
  display: table;
  margin: 15px;
  height: 500px;
  width: 100%;
  transition-duration: 0.15s;
  border: 2px solid #3B3B3B;
}
<div class="content">
  <div id="container">
    <div style="grid-area: sideone;">
      <p>あ - ა</p>
      <p>い - ი</p>
      <p>う - უ</p>
      <p>え - ე</p>
      <p>お - ო</p>
    </div>
    <div style="grid-area: sidetwo">
      <p>か - კა</p>
      <p>さ - სა</p>
      <p>た - ტა</p>
      <p>な - მა</p>
      <p>は - ჰა</p>
    </div>
    <div style="grid-area: sidethree">
      <p>き - კი</p>
      <p>し - ში</p>
      <p>ち - ჩი</p>
      <p>に - ნი</p>
      <p>み - მი</p>
    </div>
  </div>
</div>

【问题讨论】:

    标签: html css


    【解决方案1】:

    margin:0px auto; 添加到 .content 中,它应该与容器的中心对齐。

    它应该看起来像这样:

    .content {
      display: table;
      margin: 15px;
      height: 500px;
      width: 100%;
      transition-duration: 0.15s;
      border: 2px solid #3B3B3B;
      margin:0px auto;
    }
    

    【讨论】:

    • 它没有用,但我已经通过添加额外的 &lt;div&gt;display: table-cell; 解决了它。
    • 很奇怪,我已经在我的电脑上测试了代码并且它工作正常,但很高兴你自己找到了解决方案。
    猜你喜欢
    • 1970-01-01
    • 2013-09-10
    • 2018-10-24
    • 2017-03-03
    • 1970-01-01
    • 1970-01-01
    • 2012-06-13
    相关资源
    最近更新 更多