【问题标题】:Centering a div with a fixed height [duplicate]以固定高度居中 div [重复]
【发布时间】:2016-12-23 10:25:29
【问题描述】:

下面是出现的内容:

这是我的代码:

<div style="height:300px;">

<div style="height:300px;float:left;width:50%;">
    <div style="height:200px;width:70%;margin:auto; background-color:pink;"></div>

</div>
<div style="float:right;width:49%;">


</div>

我已经设置了高度,我想垂直对齐中间的粉红色框,但margin 不起作用。我该怎么做?

【问题讨论】:

    标签: html css


    【解决方案1】:

    您可以轻松实现

    display:inline-block;
    vertical-align: middle;
    margin : 0 auto;
    

    【讨论】:

      【解决方案2】:

      将此样式添加到您的粉红色框 div。

      position: relative;
      top: 50%;
      transform: translateY(-50%);
      -ms-transform: translateY(-50%);
      -webkit-transform: translateY(-50%);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-06-08
        • 1970-01-01
        • 2017-10-13
        • 2012-05-17
        • 2017-07-28
        • 2011-03-10
        相关资源
        最近更新 更多