Regarding the issue of CSS controlling the horizontal centering of DIVs, I see that many newcomers are confused. I remember the first time I read CSS was a book written by a foreigner, and it talked about the use of centering.
margin-left:auto; margin-right:auto; |
In fact, it is equivalent to:
margin:0 auto; |
So you can use this method, but some people found that it was not centered when using IE. It is recommended that you check if you are missing a DTD declaration.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> |
margin-left:50%; |
Sometimes you will find that these two are not enough. Not compatible with some browsers. So I found a third method, which mainly considers IE, and is based on the first method. It requires setting body.
body {text-align: center;} |
The above text is just an after-dinner reference and sketch. Everyone can pay attention to it in actual work!