142), collapsing margins
(p. 148), containing blocks (p. 147), and floating and clearing (p. 180) to understand
exactly how margins work for all elements. The section on inline formatting (p. 166)
also explains how margins affect inline elements.
Also see The CSS Box Model (p. 142) for an overview of how margins are handled
in relation to an element??™s borders, padding, and width.
Value
The shorthand property margin allows all four sides of an element??™s margins to be
set using either one, two, three or four specified values. Refer to the mnemonic
(TRouBLe) in Shorthand Properties (p. 39) as an easy way to remember the shorthand
order of margins.
The property takes a CSS length (px, pt, em, and so on), the keyword auto, or a
percentage of the width of the element??™s containing block (p. 147). Note that even
The Ultimate CSS Reference 210
for the top and bottom margins the percentage value will refer to the width of the
containing block. If the containing block??™s width depends on the element to which
percentage margins are applied, the resulting layout is undefined in CSS2.
Pages:
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321