Right now I have a website which has an overall height set at 750px. I have it vertically centered using the position absolute and negative margin method. It works great apart from one problem.
If I try use it on a lower-res monitor or mobile device it cuts the top of the page.
Here is my code
HTML
<body>
<div class="content">
CONTENT IS HERE
</div>
</body>
CSS
.content {
position:absolute;
top:50%;
height:750px;
margin-top:-375px; /* Half of 750px */
}
I tried using overflow:scroll; on the body tag but I understand that it doesn’t work, I didn’t expect it to. I am totally stumped! Is there any suggestion?
You can overwrite it with a mediaquery on small screens:
Actually, this is a graceful degradation method, but if you’re designing for mobile you probably want to approach in a progressive enhancement way. In that case, it becomes:
Speaking about compatibility, the
onlykeyword after@mediaprevent older browsers from rendering the rules contained.To reach (almost) full compatibility, you can use this very useful plugin: respond.js