I am trying to vertically center text inside a div that is positioned absolutely.
I tried the table-cell approach with no luck. This is a responsive layout, so I try to avoid setting fixed heights and prefer not to use Javascript.
thanks
Link to jsbin demo
HTML and CSS:
<div class="page-banner" style="background: url(http://www.bimga.com.php53-3.ord1-1.websitetestlink.com//wp-content/uploads/BIMGA_Website_InteriorPage_Banners_About.jpg) no-repeat scroll 0 0 / cover transparent"> <img style="visibility:hidden" src="http://www.bimga.com.php53-3.ord1-1.websitetestlink.com//wp-content/uploads/BIMGA_Website_InteriorPage_Banners_About.jpg"> <div class="left"> <div class="page-banner-text">this text needs to be verticall centered</div> </div> </div> <style type="text/css"> .page-banner { margin-bottom: 35px; list-style: none; width: 100%; padding-left: 0; position: relative; } .page-banner img { width: 100%; height: auto; } .page-banner .left { background-color: rgba(10, 65, 142, .75); position: absolute; z-index: 1; left: 0; top: 0; height: 100%; text-align: center; width: 50%; } </style>
source share