Home  >  Article  >  Web Front-end  >  How to center a div horizontally_html/css_WEB-ITnose

How to center a div horizontally_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:40:042075browse

How to center a div horizontally:

Having the entire div horizontally centered is used quite frequently. For example, generally the web page is centered horizontally in the browser.

Code example:

<!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>

The above code achieves the effect of horizontally centering the div. This effect can be achieved by adding margin:0px auto to the object. Finally, I would like to add that if the div does not have a width value set, margin:0px auto is invalid.

The original address is: http://www.51texiao.cn/div_cssjiaocheng/2015/0519/1896.html

The most original address is: http://www.softwhy.com/ forum.php?mod=viewthread&tid=4704

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn