您的位置:首页 > 其它

margin: 0 auto;和text-align: center;的区别

2016-10-09 13:37 645 查看

1,

margin: 0 auto;


一般使用在有宽度的框,使框在浏览器里居中。

2,

text-align: center;


使其中的内容水平居中。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
div {
height: 100px;
width: 500px;
margin: 0 auto;
text-align: center;
}
a {
display: inline-block;
height: 58px;
width: 120px;
background:red;
text-align: center;
line-height: 50px;
}
</style>
</head>
<body>
<div>
<a class="a1" href="#">导航1</a>
<a class="a2" href="#">导航2</a>
<a class="a3" href="#">导航3</a>
</div>
</body>
</html>


div里的

margin: 0 auto;/*用于设置div块居于浏览器中间*/
text-align: center;/*用于设置div块中的内容(a标签)居于整个div宽度的中间*/


结果预览:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: