Home >Web Front-end >CSS Tutorial >When to use padding in css

When to use padding in css

青灯夜游
青灯夜游Original
2020-12-18 11:38:292197browse

When padding should be used in css: 1. When you need to add a blank space to the border; 2. When the blank space needs to be filled with background (color); 3. The blank space between two boxes connected up and down, I hope When equal to the sum of the two.

When to use padding in css

Recommended: "css video tutorial"

Margin and padding often have the same effect in many places, and You can’t say that this one must use margin and that one must use padding, because the actual effect is the same. You say margin is better, but others say padding is better, but the argument is often fruitless. Based on the summary on the Internet, I found that these are relatively reliable:

When should padding be used:

  • needs to be within the border Test when adding blanks.

  • When the blank space requires a background (color).

  • The space between the two boxes connected up and down is expected to be equal to the sum of the two. For example, a 15px 20px padding will result in a 35px blank space.

When should margin be used:

  • When you need to add space outside the border.

  • When the blank space does not require a background (color).

  • The space between two boxes connected up and down needs to offset each other. For example, a margin of 15px and 20px will result in a 20px margin.

For more programming-related knowledge, please visit: Introduction to Programming! !

The above is the detailed content of When to use padding in css. 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