1

.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>

I want to push my select element to center vertically.

Cody Jonas
  • 151
  • 6

2 Answers2

1

Try flexbox with align-items set to center.

.qty_wrap {
  height: 100px;
  background: silver;
  position: absolute;
  display: flex;
  align-items: center;
}
<div class="qty_wrap">
  <select>
    <option>Blue</option>
    <option selected>Green</option>
    <option>Red</option>
  </select>
</div>

It is not clear why you set the container to position:absolute, if that is only for making it the same width as the select box, you can actually achieve that by using display:inline-flex.

.qty_wrap {
  height: 100px;
  background: silver;
  display: inline-flex;
  align-items: center;
}
<div class="qty_wrap">
  <select>
    <option>Blue</option>
    <option selected>Green</option>
    <option>Red</option>
  </select>
</div>
Stickers
  • 75,527
  • 23
  • 147
  • 186
0

for future: Using transform with top: 50% is another solution. if you don't like to use new attributes like 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>
Pedram
  • 15,766
  • 10
  • 44
  • 73