Home > Web Front-end > HTML Tutorial > 聊聊css水平垂直居中那些事_html/css_WEB-ITnose

聊聊css水平垂直居中那些事_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 09:05:42
Original
1452 people have browsed it

1、水平居中实现方法

<div class="demo">    我是一个水平居中的div</div>
Copy after login
/*方法1*/.demo{width: 960px;margin: 0 auto;}		/*方法2*/.demo{width: 960px;height: 400px;background: #f00;position: relative;left: 50%;margin-left: -480px;}
Copy after login

2、水平垂直居中实现方法

<div class="demo">    我是一个水平垂直居中的div</div>
Copy after login
/*方法1:无兼容性问题*/.demo{width: 400px;height: 400px;background: #f00;position: absolute;top: 50%;left: 50%;margin: -200px 0 0 -200px;}
Copy after login
/*方法2: 在ie7浏览器下不支持*/.demo{width: 400px;height: 400px;background: #f00;position: absolute;top: 0;left: 0;right: 0;bottom: 0;margin: auto;}
Copy after login






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