20

When using CSS what little tricks have you done to remember (perhaps a saying?) the order of left, top, right, bottom when defining combined CSS attributes such as border, margin and padding.

I'm forever forgetting and Google seems populated with crap like W3Schools.

Zistoloen
  • 10,036
  • 6
  • 35
  • 59
Mâtt Frëëman
  • 303
  • 2
  • 6

5 Answers5

24

They all go clockwise, starting from top.

Su'
  • 19,332
  • 3
  • 41
  • 65
John Conde
  • 86,255
  • 27
  • 146
  • 241
  • 4
    Except background positioning (which seems a little relevant in this case), opting for left offset first, then top offset second. – Marcel May 21 '11 at 06:50
  • @Marcel, very true, which explains why I always get that one wrong the first time. – John Conde May 21 '11 at 06:55
  • background positioning is ordered for x-y coordinates which is more reasonable when you're using numeric values, rather than left top. – zzzzBov Feb 01 '13 at 20:36
20

CSS is trouble. T-R-B-L Top-Right-Bottom-Left

Ray Mitchell
  • 486
  • 5
  • 13
8

I remember it by visualising a clock face: starting at 12 o'clock (top), then moving to 3 o'clock (right), then 6 o'clock (bottom) and finally 9 o'clock (left).

Nick
  • 20,466
  • 4
  • 44
  • 81
5

In addition to the straightforward winding analogy, I offer another mnemonic: Top, Right, Bottom, Left gives the initialism TRBL, pronounced terrible—or trouble if you like. (Hey, even treble gives me trouble as a baritone.) It fits in well with CRAP (Contrast, Repetition, Alignment, Proximity), the four principles of sound Web design.

Jon Purdy
  • 151
  • 3
2

practice

I don't recall ever using any special method of memorization for this little tidbit. I do know I learned they were set in the clockwise order from the top, but then I proceeded to write a lot of CSS.

When you do a task repeatedly there is a tendency to memorize the details for efficiency, so at this point:

  1. all
  2. top&bottom right&left
  3. top right&left bottom
  4. top right bottom left

is second nature. Just like:

border: <width> <style> <color>;

and

background: <color> <image> <repeat> <attachment> <position>;
zzzzBov
  • 325
  • 3
  • 13