操作方法
1.新建一个html页面,在页面上创建一个div,为了看得更清楚一些,对div设置一个宽、高、和背景色。如图所示:
2.在css样式上加上 marig:0 atuo后居然div水平居中了,是不是很神奇呢。 如图所示:
页面代码: <!doctype html> <html> <head> <meta charset="utf-8"> <title>div水平居中显示</title> <style type="text/css"> .mar{ width:960px; height:300px; background-color:#F90; margin:0 auto; } </style> </head> <body> <div class="mar"> </div> </body> </html>