CSS, nested divs & margins vs. padding?

Personally, I prefer option A. Why? Say now I have to add other HTML elements into the div and I want the padding to be maintained, I would not have to add other rules to my CSS files to get it working.

For me, this is the best answer. But you must consider your specific situation. See "Itay Moav's" answer.

– jon Sep 14 '09 at 5:52.

It depends on what you're trying to accomplish visually. Would container have other child elements which might hang over into the gutter on either side of the paragraph? If so, a margin makes more sense.

But if container should have a 12-pixel gutter for all elements, period, it makes the most sense to use the padding to avoid having to apply margins to multiple element sets. Generally speaking you always want paragraphs to have vertical margins to ensure consistent paragraph leading.

– jon Sep 14 '09 at 3:15 @jon the gutter is the unused space on one or more sides of text. It's different from a margin because it might make sense for a graphical element to hang into the gutter. – Rex M Sep 14 '09 at 3:17 thanks for explaining!

– jon Sep 14 '09 at 3:19.

Personally, I'd go with option a of #container {padding: 12px;} because it makes amply clear that all child elements must stay 12px away from the border of this div. If I want other elements to stay more than 12px away from the #container's border, then I apply as much more margin to that element. Cheers!

Vertical padding on the division - because if I decided I wanted a different amount of vertical space in between the multiple paragraphs I'd use bottom margins, and the top/bottom padding of the enclosing division pretty much will always stay intact assuming you just have staticly positioned elements inside.

The difference is where the border sits. The border sits SMACK DAB in the middle of the margins and padding. If you specify margins, that is white space OUTSIDE the border.

If you specify padding, that is white space INSIDE the border (pushes the border further out from the element) Can't show you here due to css stripping, but try this out: I have margins, padding and a border. I have margins, and a border. I have padding and a border.

Other stuff! Padding brings in background color of the element, margins are basically transparent some elements ( like td ) seem to ignore margins, while they respond to changes in padding.

Right. But what about when there's no border involved? :) – jon Sep 14 '09 at 3:19 A few things to consider: - padding brings in background color of the element, margins are basically transparent - some elements ( like td ) seem to ignore margins, while they respond to changes in padding – bobobobo Sep 14 '09 at 3:40.

Paddings and margins gives the same effect, Except in the following cases (I might miss some): You have some kind of background properties. Margins won't get them. You have a border You use TD (no margins) Two nested items, The margins are collapsed together, where paddings not.(need to check this one) They probably affect the width and height of the element differently.(If some one knows better, pls edit this).

But if container should have a 12-pixel gutter for all elements, period, it makes the most sense to use the padding to avoid having to apply margins to multiple element sets. Generally speaking you always want paragraphs to have vertical margins to ensure consistent paragraph leading.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions