How do you use CSS to keep a div centered forever?

Source: Internet
Author: User
Regardless of how the screen slides, the p remains in the center of the screen (supports IE7 (including IE7)

The following is a simple code to implement this function, please you can refer to.

<p class= "Loginbox" ></p>

The CSS section should write this way:

. loginbox {    background: #FA2;    width:700px;    height:400px;    position:fixed;    left:50%;    top:50%;    z-index:11;    /* Set the negative value of the P margin-top to one half of its height, and the margin-left is a negative half of its width. *//////     * Width is 400, then margin-top is -200px*//     * The height is 200 then margin-left is -100px;*/     margin: -200px 0 0-350px;}

After writing, it is so simple, is not it feel unexpected.

"Recommended"

1. Free CSS Online video tutorial

2. CSS Online Manual

3. php.cn Lonely Nine-base (2)-css video tutorial

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.