首页 > 解决方案 > 对齐

在垂直中心

问题描述

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

我想要文本并#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>あ - ა&lt;/p>
      <p>い - ი&lt;/p>
      <p>う - უ&lt;/p>
      <p>え - ე&lt;/p>
      <p>お - ო&lt;/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>

标签: htmlcss

解决方案


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

它应该看起来像这样:

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

推荐阅读