- This topic has 3 replies, 4 voices, and was last updated 10 years, 4 months ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hey, I have an issue that I’ve never really considered before:
I build all my sites on a laptop. My laptop’s screen is only 13 inches. I recently took a look at one of my sites on my friends HUGE monitor.
Alas, all my content on non-scrollable pages looked awkwardly short and high on the screen.
Is there a way to center the entire body on the y axis? I.e. up and down?
Any help is greatly appreciated.
There are a few ways to do it, it’s definitely one of the overlooked things of design. Vertical alignment is shaky at best.
The best results I’ve turned are from using a setup similar to this:
body {display:table;height:100%;width:100%;}
header,main,footer{display:table-row;width:100%;}
main {height:80%}
header,footer {height:10%}
At this point you could set vertical alignment as all height is set in the parent elements. Gets rather wonky if you attempt to have a responsive design site, so I suggest using progressive enhancement with block and inline-block level elements first then transitioning to the table method with media queries.
If you does not mind targetting quite modern browsers only you can use pseudo elements:
html, body { height: 100%; }
body { text-align: center; }
body::before
{
content: ”;
display: inline-block;
height: 100%;
vertical-align: middle;
}
#content
{
display: inline-block;
}
here’s an exemple : http://codepen.io/maxisix/pen/sEBla