css - padding:2em 2em 0;和padding:2em 2em 0 0;的区别?
伊谢尔伦
伊谢尔伦 2017-04-17 13:37:02
0
7
1023

padding:2em 2em 0;和padding:2em 2em 0 0;的区别?
还有padding:0 2em 1em 和padding:0 0 2em 1em的区别?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(7)
Peter_Zhu

Padding, margin, border-width and the like are all rules of this kind (can be understood in this way, but it seems that the standard is not written this way)
Four values ​​
The first value controls Up, down, left, and right, the second value controls left and right, the third value controls down, and the fourth value controls left.
At the same time, the later value will overwrite the earlier value.

============================================
Just now I looked through w3c (link)
This is what it said

The 'padding' property is a shorthand property for setting 'padding-top', 'padding-right', 'padding-bottom', and 'padding-left' at the same place in the style sheet.

If there is only one component value, it applies to all sides. If there are two values, the top and bottom paddings are set to the first value and the right and left paddings are set to the second. If there are three values, the top is set to the first value, the left and right are set to the second, and the bottom is set to the third. If there are four values, they apply to the top, right, bottom, and left, respectively .

Top padding, right padding, bottom padding, left padding in order
If there is only one value, then it is applied in all (four) directions
If there are only two values , then the first value is the top and bottom padding, and the second value is the right and left padding
If there are only three values, the first value is the top padding, and the second value is the left and right margins, The third value is the bottom padding
. If there are four values, the order is, top padding, right padding, bottom padding, left padding

黄舟

Top, right, bottom, left. If any one is not written, it will be the same as the opposite.

Peter_Zhu
  • top right bottom left

  • top (right & left ) bottom

  • (top & bottom )(right & left )

  • (all)

Peter_Zhu

padding:2em 2em 0; is equivalent to padding:2em 2em 0 2em; (if you don’t set a value for “left”, it will be the same as your “right” value by default)

Peter_Zhu

Padding, margin, the control of these two attributes are similar, but the range of control is different.
Padding is the inner margin, that is, the range from content to border.
Margin is the outer margin, which is the size of the range outside the border.
Generally speaking. It can have four values, namely top (top), right (right), bottom (bottom), left (left), in the clockwise direction.
If it is a value: it means that the top, right, bottom and left are all this value.
If there are two values: the first value is up and down, and the second value is left and right.
If there are three values: the first one is up and down, the second value is right, and the third one is left.
If there are four values: first, second, third and fourth, they are the values ​​​​for top, right, bottom and left respectively.

So the difference between padding:0 2em 1em and padding:0 0 2em 1em is
The first one: up and down is 0, right is 2em, and left is 1em.
Second one: Top is 0, right is 0, bottom is 2em, left is 1em.

刘奇

The settings of margin and padding follow clockwise rotation,
for example

padding: 0 2em;  第一个值设置的是上下,第二个值设置的是左右;
padding: 0 2em 0; 第一个值是上,第二个值是左右,第三个值就是下;
padding 0 2em 0 2em;  就是顺时针转了,上右下左了。
伊谢尔伦

You can refer to the figure below for the number of different parameters:

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template