【问题标题】:Vertical div centering垂直 div 居中
【发布时间】:2017-01-25 22:25:52
【问题描述】:

我在尝试垂直对齐 div 时有点吃力。我的目标是拥有 3 个高度为 100% 和宽度为 33% 的 div 以拥有居中的内容 div。任何人都可以帮忙吗?代码如下:

.wrapper {
  height: 100%;
  width: 100%;
}
.window {
  width: 33%;
  float: left;
  background-color: #666;
}
.windowContent {
  background-color: #000;
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>

<body>
  <div class="wrapper">
    <div class="window">
      <div class="windowContent">
      </div>
    </div>

    <div class="window">
      <div class="windowContent">
      </div>
    </div>

    <div class="window">
      <div class="windowContent">
      </div>
    </div>

  </div>

</body>

</html>

【问题讨论】:

标签: html css centering


【解决方案1】:

试试这个例子

<div class="wrapper">
    <div class="window">
        <div class="windowContent">
        1
        </div>
    </div>

    <div class="window">
        <div class="windowContent">
        2
        </div>
    </div>

<div class="window">
        <div class="windowContent">
        3
        </div>
    </div>

</div>

CSS

.wrapper
    {
      height: 100%;
      width: 100%;
      display: flex;
    }

    .window
    {
      width: 100%;
      min-height: 200px;
      background-color: #666;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .windowContent
    {
      background-color: #000;
      color: #fff;
    }

演示 - https://jsfiddle.net/xa3v1c3o/

【讨论】:

    猜你喜欢
    • 2011-07-07
    • 2014-09-16
    • 1970-01-01
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-30
    • 2014-08-23
    相关资源
    最近更新 更多