Vertically middle and doctype

The text “centerBox” at is vertically middle aligned.

The page above has not declared “!DOCTYPE HTML”.

Since I like to delcare the DOCTYPE,
I did it at the page below
The page below doesn’t aligned the text “centerBox” vertically middle because it has “!DOCTYPE HTML”.

The code in index.php and the code in index2.php are all same but the code in index.php has no “DOCTYPE” while the code in index2.php has it.

How can I make the text “centerBox” vertically middle with “!DOCTYPE HTML”?

1 Like

An easy way these days is to use something like display: flex:

<div class="container">
.container {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;

Add this:


Or do what Ralph says if only modern browser support is required.:slight_smile:


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.