Margin related techniques for Box Models !, Box margin

Source: Internet
Author: User

Margin related techniques for Box Models !, Box margin

If you are not talking nonsense, go to the topic and use margin-related techniques.

1. Set the horizontal center of elements: margin: x auto;

2. The negative value of margin merges the element displacement and border.

Outer margin merge

When two vertical margins meet, they form an outer margin. The height of the merged margin is equal to the larger of the two merged margins.

How to solve the outer margin merge:

A. Use this feature.

B. Set the margin on one side. Generally, set margin-top.

C. Float or locate an element (when the element is floating or positioned, there will be no margin merge)

Margin-top collapse

When two boxes are nested, the margin-top set in the internal box is added to the outer box, causing the internal box margin-top setting to fail. The solution is as follows:

A. Set a border for the external box

B. Set overflow: hidden for the external box.

C. Use pseudo element classes:

. Clearfix: before {

Content :'';

Dispaly: table;

}

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.