Give help. Get help.

  • # May 30, 2013 at 1:18 pm

    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.

    # May 30, 2013 at 2:36 pm

    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%;}
    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.

    # May 30, 2013 at 2:48 pm

    If you does not mind targetting quite modern browsers only you can use pseudo elements:

    html, body { height: 100%; }
    body { text-align: center; }
    content: ”;
    display: inline-block;
    height: 100%;
    vertical-align: middle;
    display: inline-block;

    # May 30, 2013 at 4:01 pm

    here’s an exemple :

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.