I have this to fill a window:
html, body { height: 100%;}
then the container also sets the height: 100%, how to vertically center the div with the image without specifying and setting the height in pixels and without , using absolute positioning? Using padding-top: 50%; lower dose 50%; not working - it seems to shift the div depending on the device’s site or browser window.
You can use display:tableand display:table-cell:
display:table
display:table-cell
html, body { width: 100%; height: 100%; } body{ margin: 0; display: table } body>div { display: table-cell; text-align: center; /* horizontal */ vertical-align: middle; /* vertical */ }
<div> <img src="http://paw.princeton.edu/issues/2012/07/11/pages/6994/C-beer.jpg" /> </div>
Jsfiddle
Read more about display properties .
, display:table table-cell , , <table>. :
table-cell
<table>
html, body { height: 100%; width: 100%; margin: 0; } html { display: table; } body { display: table-cell; vertical-align: middle; }
, , . , : . div html body.