Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi gurus,

Sorry I haven't been active around here over the last few months, I've
been rushed off my feet with work... which I suppose is a good thing :D

Anyway, my question is this: what is the default padding and margin on
<p>? Does it vary between browsers?

The reason I ask, is because I've been given a design to develop the PHP
for and part of the CSS is:

p {
margin: 0;
padding: 0;

As far as I can see, he's done this for styling reasons for parts other
than the main text, but it of course means in bodies of text, paragraphs
run together.  I could just remove the CSS above, but that breaks other
parts so I was wondering if I could just do...

#content p {
margin: something;
padding: something;

... to put the main body of text back to the normal margin and padding...?

Any suggestions would be appreciated.



Re: Styling

Marc wrote:

Quoted text here. Click to load it

Who knows? You'd have to ask the browser makers  (list handling
certainly varies)

This isn't the best source to use anyway - as you're implementing an
"any browser" solution, then starting from a specific browser could be
misleading. Better to aim at a true "default", although obviously that
can only be a guide, not a definitive statement.

Here's the W3C one

p  { margin: 1.12em 0 }

Re: Styling

Quoted text here. Click to load it

Indeed. But it surely varies between browsers.

Quoted text here. Click to load it

I don't think we should worry too much about a "default", if we are changing
the styling anyway. But we should set both margin and padding if we set one
of them; Marc actually referred to this in the original question, by
mentioning both properties. Otherwise we would take the risk of setting some
margin and getting more spacing just because some browser has a default
nonzero padding, or vice versa.

Quoted text here. Click to load it

Well, the "sample style sheet for HTML 4.0" is largely misleading. It
presents itself as both descriptive ("based on extensive research into
current UA practice") and prescriptive ("Developers are encouraged to use it
as a default style sheet"). In reality, it fails on both accounts. It's a
mess, a mixture of common defaults, wishful thinking, and bad ideas.

The fancy number 1.12em reflects an assumed line height of 1.12, which is
too small for commonly used fonts like Arial and which corresponds to actual
browser defaults only by accident. On the other hand, do we really need an
empty line's worth of spacing?

Marc seems to want to revert to "normal" margins for paragraphs inside an
element, assuming that some specific setting applies to the page as a whole.
That's a quite reasonable request, except that it's impossible in CSS as
currently defined.

But setting e.g.
  #content p { margin: 1em 0; padding: 0; }
should work reasonably. We don't need any specific default but something
reasonably normal. Instead 1em, you can use a somewhat different value.

Jukka K. Korpela ("Yucca")

Site Timeline