Questions about centering the absolute (fixed) position

Source: Internet
Author: User

    • About the absolute (fixed) centering problem 2016-05-29 02:51:52

The first type:

div{Position:absolute;background: #f60;width:200px;height:200px;left:50%;top:50%;margin:-100px 0 0-100px;}Note: The parent element of the DIV is the body

The second type:

first of all, we have seen the Margin:auto in the layout of the page margin:0 auto; Let the page in the Bureau, Margin:auto; it is just the same as he is not let the page around the office, but he is up and down around the bureau, Margin:auto; Let the upper and lower left and right auto. Then the problem is not solved. Attached Codediv{Position:absolute;background: #f60;left:0;top:0;right:0;bottom:0;Margin:auto;} Third Kind
 div{Position:absolute;width:200px;height:200px;background: #f60;left:50%;top:50%;-webkit-transform:translate ( -50%,-50%);-moz-transform:translate ( -50%,-50%);transform:translate ( -50%,-50%);}transform:translate ( -50%,-50%), is to let Div offset its own 50%, the size of this div computer will help you calculate, there is absolutely no need to take their own than where the calculation is also afraid of the wrong. The above positioning can also be fixed positioning, the same effect, here is not much to explain, but Tansform belongs to CSS3, the lower version of the browser is not supported .

Questions about centering the absolute (fixed) position

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.