Questions about centering

Source: Internet
Author: User

Talk about the center on the gas, said the center can see work experience, I summed up a few, we can refer to the next 1, the center of the element within the line

This is not much to say, horizontal center with Text-align:center, vertical center with line-hight: high value

2. Center of block-level element with known wide height
<!        DOCTYPE html>{margin:0; padding:0;                } #one {width:400px;                height:400px;                border:1px solid red; position:relative;/*The parent box should be positioned relatively*/} #two {width:100px;                height:100px;                BORDER:1PX solid blue; Position:absolute;/*The sub-box must be absolutely positioned*/Left :50%; Top:50%; Margin-top: -50px;/*offset up to half of its height*/margin-left: -50px;/*half of its width to the left*/            }                        </style> 3. Table-cell of block-level elements with unknown width and height
<!         DOCTYPE html>{margin:0; padding:0;                } #one {width:400px;                height:400px;                border:1px solid red; Display:table-cell; Vertical-Align:middle; Text-Align:center;                } #two {width:100px;                height:100px;                BORDER:1PX solid blue; Display:inline-block;/*must be converted to inline elements*/            }                                </style> 4. Transform of block-level elements with unknown width and height
<! DOCTYPE html>{margin:0; padding:0;                } #one {width:400px;                height:400px;                border:1px solid red;                                        position:relative;                } #two {width:100px;                height:100px;                BORDER:1PX solid blue; Left:50%; Top:50%; -webkit-transform:translate (-50%,-50%);            Position:absolute; }                                </style> 5, unknown width of the block-level elements of the center of the Elastic box layout
<! DOCTYPE html>{margin:0; padding:0;                } #one {width:400px;                height:400px;                border:1px solid red;                Display:flex; Justify-content:center;/*Center Horizontally*/Align-items:center;/*Center Vertically*/} #two {width:100px;                height:100px;            BORDER:1PX solid blue; }                                </style> 


Questions about centering

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.