码迷,mamicode.com
首页 > 其他好文 > 详细

如何让div水平居中

时间:2015-08-13 01:07:14      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:

如何让div水平居中:

让整个div水平居中的使用相当频繁。例如,一般情况下都是让网页页面在浏览器中水平居中。

代码实例:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset=" utf-8"> 
<meta name="author" content="http://www.51texiao.cn/" />
<title>蚂蚁部落</title>
<style type="text/css"> 
.mytest{ 
  width:200px; 
  height:200px; 
  border:1px solid red; 
  margin:0px auto; 
} 
</style> 
</head> 
<body> 
<div class="mytest">蚂蚁部落</div> 
</body> 
</html>

上面的代码实现了将div水平居中效果,给对象添加margin:0px auto即可实现此效果。最后再补充一句,如果div没有设置宽度值的话,margin:0px auto是无效的。

原文地址是:http://www.51texiao.cn/div_cssjiaocheng/2015/0519/1896.html

最为原始地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=4704

如何让div水平居中

标签:

原文地址:http://www.cnblogs.com/softwhy/p/4725886.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!