<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < Html Xmlns = "Http://www.w3.org/1999/xhtml" Lang = "ZH-CN" > < Head > < Meta HTTP-equiv = "Content-Type" Content = "Text/html; charsets = UTF-8" /> < Title > Horizontal vertical center Div demonstration effect </ Title > < Style Type = "Text/CSS" > . Align-center { /* Negative margin + positioning: negative margin uses absolute positioning to locate the content point to the center of the body, and then uses negative margin (half of the content width ), pull the content center back to the center of the body, which has reached the vertical center effect. */ Position : Absolute ; Left : 50% ; Top : 50% ; Width : 400px ; Height : 400px ; Margin-top : -200px ; Margin-left : -200px ; Border : 1px dashed #333 ; } </ Style > </ Head > < Body > < Div Class = "Align-Center" > Horizontal vertical center Div demonstration effect </ Div > </ Body > </ Html >