css article absolute positioning element centering techniques

高洛峰
Release: 2017-02-13 14:27:05
Original
1758 people have browsed it

Generally, the absolute positioning element is centered, left:50%;top:50%; the effect can also be achieved by using negative margin or transform.
I discovered another trick today. Use top, left, right, and bottom to set the value to 0, and then magin:auto to achieve centering.
Reason:

<div class=&#39;box>
    <div class=&#39;jz&#39;></div>
</div>
Copy after login
div.box{
   position: relative;
   height: 300px;
   background: #989eaa;
}
div.fz{
   width: 100px;
   height: 100px;
   background: #499682;
   position: absolute;
   top:0;
   left: 0;
   right: 0;
   bottom: 0;
   margin:auto;
}
Copy after login

For more css articles on absolute absolute positioning element centering techniques, please pay attention to the PHP Chinese website for related articles!

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!