Use CSS to align Div horizontally and vertically

Source: Internet
Author: User
<!  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  > 

 

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.