css 实现DIV水平垂直居中于屏幕

WBOY
Release: 2016-06-01 09:53:13
Original
1070 people have browsed it

代码如下:

 
 
 

css 实现DIV水平垂直居中于屏幕
Copy after login

在线运行

以上代码将div在网页中实现了全屏居中效果,下面简单介绍一下它的实现过程。

实现原理:

将div元素设置为绝对定位,然后设置它的left和right属性值分别为50%,这个时候div并没有居中,居中的是div的左上角,所以我们还需要再将其向上和向左拉动一定的距离即可,这个距离分别是高度和宽度的一半。

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!