1

I want to horizontally align center the div with the red border and vertically align middle the image. Vertically align middle is working but horizontally align center is not working. Here is my code:

.vcenter {
  display: table-cell;
  vertical-align: middle;
}
<div class="text-center" style="border: 1px solid black;padding-bottom:10px; width:100%;height:100%;">
  <h2>xyz</h2>

  <div style="height: 500px;width: 500px;border: 1px solid red; text-align: center; margin: 0 auto" class="vcenter center-block"><img src="" alt="Cinque Terre" width="304" height="236">
  </div>

</div>
Jithin Raj P R
  • 5,957
  • 6
  • 30
  • 64

2 Answers2

2

.vcenter {
  display: flex;
  justify-content:center; //making content center;
  align-items:center; //vertical align to middle of div  
}
<div class="text-center" style="border: 1px solid black;padding-bottom:10px; width:100%;height:100%;">
  <h2>xyz</h2>

  <div style="height: 500px;width: 500px;border: 1px solid red; text-align: center; margin: 0 auto" class="vcenter center-block"><img src="" alt="Cinque Terre" width="304" height="236">
  </div>

</div>
Pushparaj
  • 1,010
  • 8
  • 22
0

.vcenter {
  display: table-cell;
  vertical-align: middle;
}
.text-center div{
  display: flex;
}
<div class="text-center" style="border: 1px solid black;padding-bottom:10px; width:100%;height:100%;">
  <h2>xyz</h2>

  <div style="height: 500px;width: 500px;border: 1px solid red; text-align: center; margin: 0 auto" class="vcenter center-block"><img src="" alt="Cinque Terre" width="304" height="236">
  </div>

</div>
Saw Zin Min Tun
  • 607
  • 3
  • 9