Home > Web Front-end > HTML Tutorial > Solution to the failure of using CSS to control DIV centering_html/css_WEB-ITnose

Solution to the failure of using CSS to control DIV centering_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:28:33
Original
1659 people have browsed it

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!

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