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