在放大和缩小HTML5中的网页时,正文应位于中心?

时间:2016-08-06 13:02:58

标签: javascript html html5 css3 web

放大时身体如何居中?出一个网页?

<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;
    }

1 个答案:

答案 0 :(得分:0)

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

&#13;
&#13;
<!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>
&#13;
&#13;
&#13;