我们如何将div集中到整个页面

时间:2017-05-31 06:38:16

标签: html css

我想垂直居中。我试过在顶部设置填充,并设置垂直对齐但不适用于移动视图。有人可以帮忙吗?

<div style="padding-top:200px;vertical-align: middle;" align="center"> 
    This is testing content
</div>

2 个答案:

答案 0 :(得分:0)

&#13;
&#13;
.box {
    width: 100px;
    height: 100px;
    background-color: red;
    flex: 1 0 0;
    margin: 3px;
    position: relative;
}
.box_text {
    color: #ffffff;
    font-size: 20px;
    font-weight: bold;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    -webkit-transform: translate(-50%, -50%);
}
&#13;
<div class="box"><span class="box_text">0</span></div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

&#13;
&#13;
.content_center {
  display: flex;
  justify-content: center;
  align-items: center; 
  width: 250px;
  height: 150px;
  border : 1px solid black;
}
&#13;
<div class="content_center col-md-6">
  Div Content
</div>
&#13;
&#13;
&#13;