Home >Web Front-end >HTML Tutorial >实现一个div在浏览器水平居中_html/css_WEB-ITnose

实现一个div在浏览器水平居中_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:20:571213browse

第一种方法:

1 div {2  margin: 0 auto;3  width: 960px;4 }

 

第二种方法(兼容IE):

body { text-align: center; }  div {    margin: 0 auto;    width: 960px;  }

 

第三种方法(不推荐):

div {  position: relative;  left: 50%;  margin-left: -480px;  width: 960px;}

 

Statement:
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