Div+css let a small div vertically center inside another big Div

Source: Internet
Author: User

Method 1:

1234567891011121314 .parent {          width:800px;          height:500px;          border:2pxsolid#000;          position:relative;} .child {            width:200px;            height:200px;            marginauto;              positionabsolute;              top0left0bottom0right0            background-colorred;}

Method 2:

1234567891011121314 .parent {            width:800px;            height:500px;            border:2pxsolid#000;            display:table-cell;            vertical-align:middle;            text-aligncenter;        }        .child {            width:200px;            height:200px;            display:inline-block;            background-colorred;        }

Method 3:

12345678910111213 .parent {            width:800px;            height:500px;            border:2pxsolid#000;            display:flex;            justify-content:center;            align-items:center;        }        .child {            width:200px;            height:200px;            background-colorred;        }

Method 4:

123456789101112131415161718 .parent {            width:800px;            height:500px;            border:2pxsolid#000;            position:relative;        }        .child {            width:300px;            height:200px;            margin:auto;            position:absolute;/*设定水平和垂直偏移父元素的50%,再根据实际长度将子元素上左挪回一半大小*/            left:50%;            top:50%;            margin-left-150px;            margin-top:-100px;            background-colorred;        }

Div+css let a small div vertically center inside another big Div

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.