将元素推到父亲身高的50%

时间:2016-04-09 02:23:54

标签: html css

.qty_wrap{
  height:100px;
  background: red;
}
<div style="position: absolute; left: 0; top: 0; z-index: 999; margin: 0 auto; bottom: 0" class="qty_wrap">
        <select>
          <option>Blue</option>
          <option selected>Green</option>
          <option>Red</option>
        </select>
      </div>

我想将select元素垂直居中。

1 个答案:

答案 0 :(得分:0)

未来

transformtop: 50%一起使用是另一种解决方案。如果您不想使用new attributes之类的flex

.qty_wrap{
  height:100px;
  background: red;
}

select {
    top: 50%;
    transform: translateY(-50%);
    position: relative;
}
<div style="position: absolute; left: 0; top: 0; z-index: 999; margin: 0 auto; bottom: 0" class="qty_wrap">
        <select>
          <option>Blue</option>
          <option selected>Green</option>
          <option>Red</option>
        </select>
      </div>

相关问题