H5 文字水平豎直居中 DIV水平居中

實現H5中的文字水平豎直居中 div水平居中

<!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>

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章