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

How to center a div horizontally_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:40:04
Original
2144 people have browsed it

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template