Skip to main content
Participating Frequently
January 4, 2018
Answered

responsive site with media queries... how to center text vertically

  • January 4, 2018
  • 1 reply
  • 3040 views

TEST PAGE http://kifergraphics.com/test-of-vertical-align.html

Here is a stripped-down page that shows my issue. When the screen is wide, the text sits at the top of a large empty space. It would be better if the text were in the middle of that space. I've tried a few methods that I found, but none that worked with media queries. How should I do this?

Thanks in advance.

    This topic has been closed for replies.
    Correct answer Nancy OShea

    There are different ways of doing this but I think this is the simplest.

    <!doctype html>

    <html lang="en">

    <head>

    <meta charset="utf-8">

    <title>Vertically Centered</title>

    <meta name="viewport" content="width=device-width, initial-scale=1">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <style>

    /**vertically aligned in medium, large displays only**/

    @media only screen and (min-width: 768px) {

    .sameheight {

        display: table;

        table-layout: fixed

    }

    .equal {

        display: table-cell;

        vertical-align: middle;

        width:50%;

    }

    }

    </style>

    </head>

    <body>

    <div class="row sameheight">

    <div class="col equal">

    Something here

    </div>

    <div class="col equal">

    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magni perspiciatis ducimus modi nobis quas, nisi molestias magnam eos quia beatae, quos omnis at, officia unde voluptatibus labore cumque repudiandae iusto.</p>

    </div>

    </div>

    </body>

    </html>

    1 reply

    Nancy OShea
    Community Expert
    Nancy OSheaCommunity ExpertCorrect answer
    Community Expert
    January 4, 2018

    There are different ways of doing this but I think this is the simplest.

    <!doctype html>

    <html lang="en">

    <head>

    <meta charset="utf-8">

    <title>Vertically Centered</title>

    <meta name="viewport" content="width=device-width, initial-scale=1">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <style>

    /**vertically aligned in medium, large displays only**/

    @media only screen and (min-width: 768px) {

    .sameheight {

        display: table;

        table-layout: fixed

    }

    .equal {

        display: table-cell;

        vertical-align: middle;

        width:50%;

    }

    }

    </style>

    </head>

    <body>

    <div class="row sameheight">

    <div class="col equal">

    Something here

    </div>

    <div class="col equal">

    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magni perspiciatis ducimus modi nobis quas, nisi molestias magnam eos quia beatae, quos omnis at, officia unde voluptatibus labore cumque repudiandae iusto.</p>

    </div>

    </div>

    </body>

    </html>

    Nancy O'Shea— Product User & Community Expert
    kazberryAuthor
    Participating Frequently
    January 5, 2018

    That works! Looks like "col" and "row" are built-in classes. I guess I need to read up on Bootstrap.

    Thank you!

    kazberryAuthor
    Participating Frequently
    January 9, 2018

    Maybe because I used online placeholder images.

    Remove mine, save.

    Reinsert yours, save.

    Switch to Live View.


    Okay it worked that time. Odd. I just needed your authority behind me I guess. Thanks, Nancy.