I am trying to center both horizontally and vertically a div inside an outer div. It works when the outer div has a specific width and height set in pixels, for example
#countdownBox { width: 700px; height: 500px; display: table-cell; vertical-align: middle; text-align: center; }
but it fails when the height and width are percentages, for example
#countdownBox { width: 100%; height: 100%; display: table-cell; vertical-align: middle; text-align: center; }
Why is this work?
EDIT Here is the HTML with the CSS container:
#countdownBoxContainer { width: 100%; height: 100%; position: absolute; bottom: 0; left: 0; z-index: 3; } <div id="countdownBoxContainer"> <div id="countdownBox"> <div> hi there </div> </div> </div>
zakdances
source share