About a div up and down centered CSS method

Source: Internet
Author: User

1: Through the Position:absolute positioning, the upper and lower values are set to 0,margin:auto; need to know the height of the div

{
width:64px;
height:64px;
border:1px solid red;
Position:absolute;
top:0;
left:0;
bottom:0;
right:0;
Margin:auto;
}

2: Need to know the width of the div, by positioning the width of the moving page half of the position, and then through the Margin-top and margin-left the width of the div to move the general can be achieved;

{

width:64px;
height:64px;
border:1px solid red;
Background-image:url (img/g2.gif);
background-size:100% 100%;
Position:absolute;
top:50%;
left:50%;
Margin-top: -32px;
Margin-left: -32px;

}

3 Unknown div width height. To be propped up by the contents of a Div

{

border:1px solid red;
Position:absolute;
top:50%;
left:50%;
-webkit-transform:translate (-50%,-50%);
-moz-transform:translate (-50%,-50%);
-ms-transform:translate (-50%,-50%);
-o-transform:translate (-50%,-50%);
Transform:translate (-50%,-50%);

}

About a div up and down centered CSS method

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.