相关疑难解决方法(0)

为什么"margin:auto"不是垂直居中的元素?

正如您在下面的演示中所看到的,margin: auto;将蓝色div水平居中,而不是垂直居中.为什么不?

.box {
  border: 1px solid red;
  width: 100px;
  height: 100px;
}
.center {
  background: blue;
  width: 50px;
  height: 50px;
  margin: auto;
}
Run Code Online (Sandbox Code Playgroud)
<div class="box">
  <div class="center"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

我的问题不是要求解决方法.

html css margin

46
推荐指数
4
解决办法
8136
查看次数

标签 统计

css ×1

html ×1

margin ×1