margin:0自动不居中? [英] margin: 0 auto not centering?
本文介绍了margin:0自动不居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Chrome,Firefox和Safari中尝试过下列程式码,但我的div并不完全集中。
I've tried the following code in Chrome, Firefox, and Safari, but my div isn't quite being centered.
HTML:
<!DOCTYPE html>
<html>
<head>
<link href="custom.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="center">Hello!</div>
</body>
</html>
custom.css:
custom.css:
.center {
width: 400px;
margin: 0 auto;
border: 5px solid black;
}
这会在Chrome中生成以下内容:
This produces the following in Chrome:
,您可以看到左边距大于
and you can see that the left margin is bigger than the right margin.
我做错了什么?
推荐答案
是因为正文有边距(默认为浏览器):
It is because the body has a margin (default for browsers):
body { margin: 0px; }
大。在您的屏幕截图中,它是:
It should look normal if your window is bigger. In your screenshot it's like:
这篇关于margin:0自动不居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文