>  기사  >  웹 프론트엔드  >  如何让div水平居中_html/css_WEB-ITnose

如何让div水平居中_html/css_WEB-ITnose

WBOY
WBOY원래의
2016-06-24 11:40:042075검색

如何让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

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.