0

How do I position my caption div vertically centre within caption-wrap?

http://jsfiddle.net/0j5e06mt/

HTML:

<div class="caption-wrap">

    <div class="caption">
        <p>test</p>
        <p>test</p>
    </div>

</div>

CSS:

.caption-wrap {background:red;height:120px;width:100%}
.caption {background:blue;text-align:center}
michaelmcgurk
  • 6,367
  • 23
  • 94
  • 190

1 Answers1

3

Try:

.caption{
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}

Source: http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/

tomexx
  • 2,301
  • 2
  • 20
  • 33
  • 2
    Don't forget the vendor prefixes to cover more browsers: -webkit-transform: translateY(-50%); -ms-transform: translateY(-50%); transform: translateY(-50%); – ala_747 Feb 17 '15 at 23:54