使用
margin-left:auto;margin-right:auto; 可以让你的div居中对齐。
.style{margin-left:auto;margin-right:auto;}
缩写形式为:
.style{margin:0 auto;}
数字0 表示上下边距是0。可以按照需要设置成不同的值。查看下面的例子:
.style{margin-left:auto;margin-right:auto;}
缩写形式为:
.style{margin:0 auto;}
数字0 表示上下边距是0。可以按照需要设置成不同的值。查看下面的例子:
<
html
>
< head >
< style type = " text/css " >
.align - center{
margin: 0 auto; /* 居中 这个是必须的 */
width:100px; /* 给个宽度 顶到浏览器的两边就看不出居中效果了 */
background:red; /* 背景色 */
text - align:center; /* 文字等内容居中 */
}
</ style >
</ head >
< body >
< div width = " 200 " height = " 200 " class = " align-center " >
dfdf
</ div >
</ body >
</ html >
< head >
< style type = " text/css " >
.align - center{
margin: 0 auto; /* 居中 这个是必须的 */
width:100px; /* 给个宽度 顶到浏览器的两边就看不出居中效果了 */
background:red; /* 背景色 */
text - align:center; /* 文字等内容居中 */
}
</ style >
</ head >
< body >
< div width = " 200 " height = " 200 " class = " align-center " >
dfdf
</ div >
</ body >
</ html >