CSS如何让div相对body居中 而其中的控件不受影响。

html-css07

CSS如何让div相对body居中 而其中的控件不受影响。,第1张

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、将index.html中的<body>替换为:

<body style="text-align: center">

<div style="margin:autowidth: 200pxheight: 70pxborder: 1px solid bluetext-align: left">

<span>123</span>

</div>

</body>

3、浏览器运行index.html页面,此时div相对body是居中,而div中的内容并没有受影响。

为body的内容加边框,就在body里面设置个div

,然后设置它的属性,比如:边框boder:1px

solid

#f00

居中:margin:auto;层里面的内容你不设置还是原来的样子。