How is the text centered vertically?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
div{
    width:300px;
    height:70px;
    border:1px solid red;
    font-size:30px;
    line-height:70px;
    vertical-align:middle; 
    text-align:center;
    padding:0px;
    margin:0px;
}
</style>
</head>
<body>
    <div>
        

hello world

</div> </body> </html>

the effect is as follows:

ling-height = divheight
vertical-align:middle;

Mar.12,2021

you limit div to death. If p spills over, of course it's not centered.
if you change the div in css to p, you will center

.
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
p{
    width:300px;
    height:70px;
    border:1px solid red;
    font-size:30px;
    line-height:70px;
    vertical-align:middle; 
    text-align:center;
    padding:0px;
    margin:0px;
}
</style>
</head>
<body>
    <div>
        

hello world

</div> </body> </html>

text is based on line height. Line-height:70px;, if you remove the default inner and outer margins, the distance you mark should be about 35


.

parent:

display: table-cell;
vertical-align: middle;
height: 65px;
width: 65px;

Child:

display: inline-block;
vertical-align: middle;

see that so many gods have given you an answer, and you haven't adopted it yet. I've decided to have an ultimate answer.
and look at the picture:

divdiv

ppchromemargin1em;
1emem
font-size1emfont-size35pxmarginmargin35px;
:pfont-size,p35px

marginOK

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37f6f-2c0cc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37f6f-2c0cc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?