H5 text is centered horizontally and vertically DIV is centered horizontally

Realize the text in H5 to be centered horizontally and vertically, div centered horizontally

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #big{
            width: 300px;
            height: 300px;
            background: green;
        }
        #small{
            width: 100px;
            height: 100px;
            background: yellow;
            /* 水平居中 */
            /* margin: 0 auto; */
            /* 不能竖直都居中 因为网页是无限拉长的*/
            margin: auto auto;
            /* 文字水平居中 */
            text-align: center;
            /* 文字竖直居中 */
            line-height: 100px;
        }
    </style>
</head>
<body>
    <div id="big">
        <div id="small">Hello</div>
    </div>
</body>
</html>

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_41526316/article/details/89737215