htmlHow to center the div: 1. Center the div by adding the "
content " tag; 2. Add the "margin:0 auto attribute;" to the div to automatically adjust it Centered.
The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.
There are two methods for DIV centering:
1. The simple and quick method is to add the
Example:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>center居中</title> </head> <body> <center> <div>我要居中啦</div> </center> </body> </html>
2. Add the margin:0 auto attribute to the div; automatically adjust the center.
Example 2:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>margin居中</title> <style type="text/css"> .d1{ border:1px solid red; width:200px; height:200px; text-align:center; line-height:40px; margin:0 auto; } </style> </head> <body> <div class="d1"> 我是div,我居中啦... </div> </body> </html>
Recommended tutorials: html video tutorial, css video tutorial
The above is the detailed content of How to center div in html. For more information, please follow other related articles on the PHP Chinese website!