div Vertical Center CSS div box up and down vertical center

Source: Internet
Author: User

created: May 24, 2015 (Sunday) 3:46 | Category: Work life | words: 459 | Save As ... | print | Add to Calendar
    1. <! DOCTYPE html>
    2. <meta charset= "Utf-8"/>
    3. <title> Vertical Center up and down online demo divcss5</title>
    4. <style>
    5. #main {position:absolute;width:400px;height:200px;left:50%;top:50%;
    6. margin-left:-200px;margin-top:-100px;border:1px Solid #00F}
    7. /*CSS Note: For convenience, wrap CSS code */
    8. </style>
    9. <body>
    10. <div id= "main" >div Horizontal and vertical center </div>
    11. </body>
Here a "#main" Object style is set, width 400px, height 200px, using absolute positioning position style while using absolute positioning left and top, and set Margin-top and Margin-left at the same time, in order to observe the effect, So a red border is added to this div box.

div Vertical Center CSS div box up and down vertical center

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.