Home  >  Article  >  Web Front-end  >  Share an article about margin related skills

Share an article about margin related skills

零下一度
零下一度Original
2017-07-03 10:12:201457browse

Without further ado, let’s go directly to the topic, margin related techniques.

1. Set the element to be horizontally centered: margin:x auto;

2. Negative margin values ​​allow the elements to be displaced and the borders merged.

Margin merging

means that when two vertical margins meet, they will form one margin. The height of the merged margin is equal to the greater of the heights of the two merged margins.

Methods to solve margin merging:

a. Use this feature.

b. Set the margin on one side, generally set margin-top

c. Float or position the element (when the element is floated or positioned, margin merging will not occur)

margin-top collapse

When two boxes are nested, the margin-top set by the inner box will be added to the outer box, causing the inner box to collapse. The box margin-top setting failed, 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 class :

 .clearfix:before{

  content:'';

  dispaly:table;

 }

The above is the detailed content of Share an article about margin related skills. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn