A friend used DIV centering, but found that DIV centering failed. What happened? Let me solve the problem for you below, haha!
1. Generally, the failure of DIV centering is because the DTD statement is not written and
is added at the top of the page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3 .org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
That's it! In fact, many other CSS problems are also caused by not adding dtd statements.
2.The simplest way
to use margin to center a DIV
is:.divstyle{ margin:0 auto; }
If it is more complicated, add both left and right margins:
.divstyle{ margin-left:auto; margin-right:auto; }
This way you can imagine that the DIV is centered!