Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 边距自动不居中内容_Css_Html_Containers_Center_Margin - Fatal编程技术网

Css 边距自动不居中内容

Css 边距自动不居中内容,css,html,containers,center,margin,Css,Html,Containers,Center,Margin,您好,我对简单CSS有一个问题。我试图通过使用margin right:auto和margin left:auto使div标记集中在我的页面上,但它似乎没有集中内容。我已经搜索了答案,但我找不到任何最简单的代码错误 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <style type="text/css"> body {

您好,我对简单CSS有一个问题。我试图通过使用margin right:auto和margin left:auto使div标记集中在我的页面上,但它似乎没有集中内容。我已经搜索了答案,但我找不到任何最简单的代码错误

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<style type="text/css">
body {
    margin-left: 0px;
    margin-right: 0px;
    margin-top: 0px;
    margin-bottom: 0px;
}

#container {
    font-family: Georgia, "Times New Roman", Times, serif;
    background-color: #666;
    height: auto;
    width: 800px;
    margin-top: 0px;
    margin-right: auto;
    margin-left: auto;
}
</style>
</head>
<body>

<div id="container">
Hello world!
</div>

</body>
</html>
将显示:表添加到容器中

#container {
    font-family: Georgia, "Times New Roman", Times, serif;
    background-color: #666;
    height: auto;
    width: 800px;
    margin-top: 0px;
    margin-right: auto;
    margin-left: auto;
    display:table;
}

它不适合你的唯一原因是你没有

<DOCTYPE html>

潜水舱对我来说是居中的。但是,其中的文本不是。我的浏览器呈现css时一定有问题。谢谢,你用什么浏览器?不是吗?如果没有doctype,任何IE都会将页面呈现为IE5,它不支持使用margin:auto居中。
margin: 0 auto;