Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.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/86.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 HTML5部门,我做错了什么?_Css_Html - Fatal编程技术网

Css HTML5部门,我做错了什么?

Css HTML5部门,我做错了什么?,css,html,Css,Html,对不起,我是个新手。我想做一个div,这样我就可以在我的页面中间做一个盒子,所有的东西都会进入这个网站。 我的HTML如下所示: <!DOCTYPE HTML PUBLIC> <html> <head> <link rel="stylesheet" type="text/css" href="CSSdoc.css" /> </head> <body> <cente

对不起,我是个新手。我想做一个div,这样我就可以在我的页面中间做一个盒子,所有的东西都会进入这个网站。 我的HTML如下所示:

<!DOCTYPE HTML PUBLIC>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="CSSdoc.css" />
    </head>
    <body>
        <center>
            <div id="mainbox">
                <p>text</p>
            </div>
        </center>
        <h1> text </h1>
        <p>text</p>
        <h2> text </h2>
        <p>text</p>
    </body>
</html>
我做错了什么

margin:auto;
这将使其在固定宽度后在中心对齐

<body style="margin:0;">
        <div  style="width:900px; margin:auto; border:1px solid #000;"  id="mainbox">
            <p>text</p>
     <h1> text </h1>

    <p>text</p>
     <h2> text </h2>

    <p>text</p>
        </div>

</body>
你的盒子区域应该有

body{
margin:0;
}
#mainbox{
width:900px; 
margin:auto;
}
HTML代码中不需要
标记;CSS将帮助您集中精力。在CSSdoc.css文件中,只需调整以下内容即可

#主框{
填充:0;
边距:0自动;/*此处的0表示顶部和底部边距间距。在许多情况下,拥有和控制边距是很好的*/
宽度:900px;
边框:实心2px#000;/*这是可选的,更多用于调试目的,以查看您的900px缩放框*/
}
#mainbox{
width:900px; 
margin:auto;
}