在HTML5中放大和缩小网页时,正文应该在中心

Body should be in center while zoom in and zoom out of web page in HTML5?

本文关键字:正文 在中心 网页 HTML5 放大 缩小      更新时间:2023-09-26

放大&出一个网页?

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
body {
        font-family: 'Merriweather Sans', sans-serif;
        margin:0px;
        font-weight: normal 300;
        font-size:14px;
        color:#595959;
        text-align:center;
    }

当我将margin: 0 auto;添加到红色div时,请注意该div的居中。尝试缩放,它将仅停留在中心。在正文的css属性中不需要text-align: center。只需将margin: 0 auto;添加到要居中的div中(我假设您希望元素水平居中(

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
    <div id = 'justCreatedThisDiv' style = 'margin: 0 auto;'>
        <!-- put all your code here -->
	<div style = "width: 100px; height: 100px; background-color: red; margin: 0 auto;"></div>
    </div>
</body>
</html>