CSS center summary, css center Summary

Source: Internet
Author: User

CSS center summary, css center Summary

1. text-align: center;

In the preceding method, the row element or text of the display: inline; in the parent container is horizontally centered.

2. inline-height: (height) value;

When using inline-height, it is often used with height to center the content vertically. It is recommended to use it in the li in the list;

3. margin: auto;

When margin is used for residence, the exact width value is usually given in the element. Setting margin: auto; or margin: 0 auto; is the same effect: the current element is horizontally centered;

When using margin, you can also set the values of margin-left and margin-right to be equal and horizontally centered;

4. Center position

You can set top, left, bottom, and right to center the elements horizontally and vertically. However, the height of the parent element must be set;

5. Flex box

Flex-align: center;

Align-items: center;

Justify-cotent: center;

Align-self: center;

6. negative value margin:

 1 .box { 2     width: 600px; 3     height: 400px; 4     position: relative; 5 }  6  7 .box1 { 8     width: 300px; 9     height: 200px;10     padding: 20px;11     position: absolute;12     top: 50%;13     left: 50%;14     margin-left: -170px;/*(width+padding)/2 */15     margin-top: -120px;/*(height+padding)/2 */16 } 

The above Code enables horizontal and vertical center of elements.

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.