用CSS控制DIV居中失效的解决方法_html/css_WEB-ITnose

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

1、一般情况下DIV居中失效是因为没写DTD语句

  在页面的最上方加上:

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  就可以了!其实其他很多css的问题也是因为没有加上dtd语句引起的。

  2、使用margin来让DIV居中

  最简单的写法就是:

  .divstyle{ margin:0 auto; }

  复杂一些就把左右边距都加上:

  .divstyle{ margin-left:auto; margin-right:auto; }

  这样就可以试想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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!