<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> div{ width: 500px; height: 200px; background-color: #cccccc; /*布局居中显示*/ margin: 0 auto; } </style> <title>margin布局居中显示</title> </head> <body> <div> 笑的大方,走的坦荡。笑的大方,走的坦荡。笑的大方,走的坦荡。笑的大方,走的坦荡。笑的大方,走的坦荡。 笑的大方,走的坦荡。笑的大方,走的坦荡。笑的大方,走的坦荡。笑的大方,走的坦荡。笑的大方,走的坦荡。 笑的大方,走的坦荡。 </div> </body> </html>
本文通过一个具体的HTML页面实例展示了如何使用CSS的margin属性来实现元素的居中布局。通过设置左右margin为auto并规定宽度或高度,可以让块级元素在页面上水平居中显示。
97

被折叠的 条评论
为什么被折叠?



