Vertically middle and doctype

The text “centerBox” at http://dot.kr/x-test/html/middleCenter/index.php 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”.

http://dot.kr/x-test/html/middleCenter/index2.php

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">
  <p>centerbox</p>
</div>
.container {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
}
2 Likes

Add this:

html,body{margin:0;padding:0;height:100%;}

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

2 Likes

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