Css 边距自动不居中内容
您好,我对简单CSS有一个问题。我试图通过使用margin right:auto和margin left:auto使div标记集中在我的页面上,但它似乎没有集中内容。我已经搜索了答案,但我找不到任何最简单的代码错误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 {
<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;