Home  >  Article  >  Web Front-end  >  css article absolute positioning element centering techniques

css article absolute positioning element centering techniques

高洛峰
高洛峰Original
2017-02-13 14:27:051817browse

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>
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;
}

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

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