2

By default the row aligns to the top.

I tried to put margin-top: auto; and margin-bottom: auto; but doesn't work. Also vertical-align: middle; also does not work.

Is there an easy fix to this?

Thanks

.container {
background-color:black;
height: 100px;
}

.row {
background-color:#fff;
height: 50px;
}
<div class="container">
  <div class="row">
  </div>
</div>
suonpera
  • 225
  • 1
  • 5
  • 13

4 Answers4

17

You can use flexbox for this:

.row {
    display: flex;
    align-items: center;
    justify-content: center;
}
Arosha De Silva
  • 597
  • 8
  • 18
Super User
  • 9,448
  • 3
  • 31
  • 47
3

Basically, this question is a duplicate. There are various centering methods for Bootstrap explained in that question. This will work specifically for your scenario with the row inside the container. Here are 2 different methods..

// method 1 flexbox
.container-flex {
    display: flex;
    align-items: center;
}

// method 2 translatey
.v-center {
    position: relative;
    transform: translatey(-50%);
    top: 50%;
}

http://www.codeply.com/go/b6wTQTzoe1

Community
  • 1
  • 1
Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
0

Set width and height for row and

.row {
    margin: 0 auto;
}
Grak T
  • 26
  • 4
0
<div class="inner">
    <p>
      Text
    </p>
</div>

.inner {
  height: 200px;
  width: 300px;
  background: orange;
  vertical-align: middle;
  display: table-cell;
}

The "Text" should be vertically aligned. Display table-cell works with vertical-align. I think it should be possible to do it with inline-elements too.