- 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