A mnemonic for the order of CSS margin and padding shorthand properties

前端 未结 22 1453
长发绾君心
长发绾君心 2021-01-30 05:20

I can never remember the order of the shorthand property for setting the margin or padding in one declaration. That is:

margin-top:    2px;
margin-bottom: 4px;
m         


        
相关标签:
22条回答
  • 2021-01-30 05:24

    Actually the clock thing works perfectly. It is the most intuitive way to remember it, at least for me.

    0 讨论(0)
  • 2021-01-30 05:26

    The clock trick works for the 4 number shortcut, but is there any logic to the 3 and 2 number shortcuts? 1 number and it applies to everything, and that makes sense, but

    1 = (T/R/b/l) 
    2 = (T=b) (R=l)   
    3 = (T) (R=l) (b)  
    4 = (T) (R) (b) (l)
    

    It just doesn't seem logical at all. But... First value pertains to Top, Second pertains to the Right, Third is the bottom and Fourth is the left; A number is not specified if it's the same as its opposite. Horizontal and vertical MUST be declared unless all values are identical.

    In other words, you always specify the Top and Right values, bottom and left fall in as required.

    0 讨论(0)
  • 2021-01-30 05:26

    Whenever you strike with a given situation, just think of a clock-wise rotation i.e., way the clock rotates from 0 to 60 in a circular rotation.

    Clock thing is easier to remember than the word TRouBLe (as marked answer) in my opinion since the word trouble belongs to English language and all those minds native to English language might find it easier to remember the word TRouBLe in relevancy to the given situation but not others who only use English language when they really have to.

    Same is not true with clock-wise rotation of a clock, when it comes to remembering something (as asked it the question) since clock-wise-rotation is a very well-known phenomena world-wise.

    0 讨论(0)
  • 2021-01-30 05:27

    Tricky Rectangle Border Logic ?

    0 讨论(0)
  • Remember driving lesson:

    Turn Right Before Left

    0 讨论(0)
  • 2021-01-30 05:29

    Just think clockwise, it's the easiest way. Starts at the top and goes around... much easier to remember than some silly phrase (provided you know how to read a clock...)

    0 讨论(0)
提交回复
热议问题