Home >Web Front-end >HTML Tutorial >Solution to the failure of using CSS to control DIV centering_html/css_WEB-ITnose
1. Generally, DIV centering fails because the DTD statement is not written
Add 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. Use margin to center the DIV
The simplest way to write it is:
.divstyle{ margin:0 auto; }
The more complicated one is Add both left and right margins:
.divstyle{ margin-left:auto; margin-right:auto; }
Then you can try to center the DIV!