DIV horizontal vertical center CSS

/ * Achieve a principle: div make other block element centered horizontally and vertically, it is necessary to know the width and height of the block-level elements like div, and then set a location for the absolute position of the window from the page on the left border and the border distance setting 50%, 
respectively, and move the left refers to the 50% to 50% of the page width and height of the window, and finally the block-level elements like div, and the left shift is the size of the block-level div element widths and other half the height. The method generally used,
but only if required width and height of the block elements and the like disposed div. If and when the page div other block element width and height are dynamic, say pop required a div like block-level elements of the element layer, and to be centered,
div contents other block-level elements are dynamic, so the width and height are also dynamic , then you need to use jQuery can be solved centrally.
* / .Mycss { width : 300px by ; height : 200px ; position : Absolute ; left : 50% ; Top : 50% ; margin : -100px -150px 0 0 } / * Achieve two principles: the use of CSS margin is set to auto allow your browser to help our own centered vertically and horizontally * / .mycss { position : Absolute ; left : 0px ; right : 0 ; Top : 0 ; bottom : 0 ; margin : auto ; height : 200px ; width : 300px by ; }

 

Guess you like

Origin www.cnblogs.com/tmdsleep/p/10984951.html