By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,766 Members | 1,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,766 IT Pros & Developers. It's quick & easy.

Default margins of elements inside table cells

P: n/a
I just noticed that most browsers render

<table border="1"><tr><td><p>foo</p></td></tr></table>

the same way as

<table border="1"><tr><td>foo</td></tr></table>

That is, they ignore the p markup in the sense that they don't apply the
normal default top and bottom margins. This is rather odd, especially
since they do leave some space between paragraphs, so they apparently
ignore just the top margin of the first paragraph and the bottom margin
of the last paragraph.

Mozilla and Opera seem to do the same with <blockquote>, <form>, and
<ul>, whereas IE applies a _bottom_ margin to them when they appear as
the sole content of a cell.

This is rather odd, and I don't know what to think about it. In any case,
whenever you put block elements inside a cell, you should probably
consider setting some CSS rules to suggest a particular rendering as
regards to top and bottom margin. And, in fact, you might affect them
without wanting to do so, since e.g.
p { margin: 1em 0; }
in an author style sheet affects p elements inside table cells, too, even
though it might have been meant to just fine tune the normal default
margins.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jul 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Jukka K. Korpela wrote:
I just noticed that most browsers render
<table border="1"><tr><td><p>foo</p></td></tr></table>
the same way as
<table border="1"><tr><td>foo</td></tr></table>

That is, they ignore the p markup in the sense that they don't apply
the normal default top and bottom margins. This is rather odd,
especially since they do leave some space between paragraphs, so they
apparently ignore just the top margin of the first paragraph and the
bottom margin of the last paragraph. [snip] This is rather odd, and I don't know what to think about it. In any
case, whenever you put block elements inside a cell, you should
probably consider setting some CSS rules to suggest a particular
rendering as regards to top and bottom margin. And, in fact, you
might affect them without wanting to do so, since e.g.
p { margin: 1em 0; }
in an author style sheet affects p elements inside table cells, too,
even though it might have been meant to just fine tune the normal
default margins.


I can't say which browser is right. But I did find the excessive margin that
Firefox leaves at the top and bottom of paragraphs in cells irritating.
Sometimes I have a data table with non-paragraph stuff in some columns, and
paragraphs in others, and I want them to line up across the screen. Netscape
7.1 hasn't been so bad as Firefox.

I typically have a rule in my CSSs such as the following:

td > h1:first-child, td > h2:first-child, td > h3:first-child, td >
h4:first-child, td > p:first-child {
margin-top: 0;
}

(I don't yet use ":last-child" because that is CSS3, and didn't validate last
time I checked. I can put up with extra space at the bottom, because it isn't
as noticeable as mis-aligned tops).

--
Barry Pearson
http://www.Barry.Pearson.name/photography/
http://www.BirdsAndAnimals.info/
http://www.ChildSupportAnalysis.co.uk/
Jul 20 '05 #2

P: n/a
Jukka K. Korpela wrote:
I just noticed that most browsers render
<table border="1"><tr><td><p>foo</p></td></tr></table>
the same way as
<table border="1"><tr><td>foo</td></tr></table>

That is, they ignore the p markup in the sense that they don't apply
the normal default top and bottom margins. This is rather odd,
especially since they do leave some space between paragraphs, so they
apparently ignore just the top margin of the first paragraph and the
bottom margin of the last paragraph. [snip] This is rather odd, and I don't know what to think about it. In any
case, whenever you put block elements inside a cell, you should
probably consider setting some CSS rules to suggest a particular
rendering as regards to top and bottom margin. And, in fact, you
might affect them without wanting to do so, since e.g.
p { margin: 1em 0; }
in an author style sheet affects p elements inside table cells, too,
even though it might have been meant to just fine tune the normal
default margins.


I can't say which browser is right. But I did find the excessive margin that
Firefox leaves at the top and bottom of paragraphs in cells irritating.
Sometimes I have a data table with non-paragraph stuff in some columns, and
paragraphs in others, and I want them to line up across the screen. Netscape
7.1 hasn't been so bad as Firefox.

I typically have a rule in my CSSs such as the following:

td > h1:first-child, td > h2:first-child, td > h3:first-child, td >
h4:first-child, td > p:first-child {
margin-top: 0;
}

(I don't yet use ":last-child" because that is CSS3, and didn't validate last
time I checked. I can put up with extra space at the bottom, because it isn't
as noticeable as mis-aligned tops).

--
Barry Pearson
http://www.Barry.Pearson.name/photography/
http://www.BirdsAndAnimals.info/
http://www.ChildSupportAnalysis.co.uk/
Jul 20 '05 #3

P: n/a
"Jukka K. Korpela" <jk******@cs.tut.fi> wrote:
I just noticed that most browsers render

<table border="1"><tr><td><p>foo</p></td></tr></table>

the same way as

<table border="1"><tr><td>foo</td></tr></table>

That is, they ignore the p markup in the sense that they don't apply the
normal default top and bottom margins. This is rather odd, especially
since they do leave some space between paragraphs, so they apparently
ignore just the top margin of the first paragraph and the bottom margin
of the last paragraph.


In Mozilla it varies between quirks and standards mode.

http://steve.pugh.net/test/test78q.html
http://steve.pugh.net/test/test78s.html

IE6 and Opera 7 - never displays the margin adjacent to the cell
top/bottom
Mozilla - displays the margins in standards mode but not quirks mode.

If the <p> elements have a border set then Opera behaves differently
again due to its implementation vertical margin collapsing.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #4

P: n/a
"Jukka K. Korpela" <jk******@cs.tut.fi> wrote:
I just noticed that most browsers render

<table border="1"><tr><td><p>foo</p></td></tr></table>

the same way as

<table border="1"><tr><td>foo</td></tr></table>

That is, they ignore the p markup in the sense that they don't apply the
normal default top and bottom margins. This is rather odd, especially
since they do leave some space between paragraphs, so they apparently
ignore just the top margin of the first paragraph and the bottom margin
of the last paragraph.


In Mozilla it varies between quirks and standards mode.

http://steve.pugh.net/test/test78q.html
http://steve.pugh.net/test/test78s.html

IE6 and Opera 7 - never displays the margin adjacent to the cell
top/bottom
Mozilla - displays the margins in standards mode but not quirks mode.

If the <p> elements have a border set then Opera behaves differently
again due to its implementation vertical margin collapsing.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #5

P: n/a
On Thu, 22 Apr 2004 17:39:23 +0100, Steve Pugh <st***@pugh.net> wrote:
"Jukka K. Korpela" <jk******@cs.tut.fi> wrote:

I just noticed that most browsers render

<table border="1"><tr><td><p>foo</p></td></tr></table>

the same way as

<table border="1"><tr><td>foo</td></tr></table>

That is, they ignore the p markup in the sense that they don't apply the
normal default top and bottom margins. This is rather odd, especially
since they do leave some space between paragraphs, so they apparently
ignore just the top margin of the first paragraph and the bottom margin
of the last paragraph.


In Mozilla it varies between quirks and standards mode.

http://steve.pugh.net/test/test78q.html
http://steve.pugh.net/test/test78s.html

IE6 and Opera 7 - never displays the margin adjacent to the cell
top/bottom
Mozilla - displays the margins in standards mode but not quirks mode.

If the <p> elements have a border set then Opera behaves differently
again due to its implementation vertical margin collapsing.


Yes. This is all reverse engineering, to make tables in CSS-based browsers
look like they did in earlier browsers, even though the CSS and HTML spec
don't call for a special treatment of these cases. If you do explicitly
style the first or last block element in a table cell, Opera will honor
that. But by default the first top and last bottom margin will be zero.

--
Rijk van Geijtenbeek

The Web is a procrastination apparatus:
It can absorb as much time as is required to ensure that you
won't get any real work done. - J.Nielsen
Jul 20 '05 #6

P: n/a
On Thu, 22 Apr 2004 17:39:23 +0100, Steve Pugh <st***@pugh.net> wrote:
"Jukka K. Korpela" <jk******@cs.tut.fi> wrote:

I just noticed that most browsers render

<table border="1"><tr><td><p>foo</p></td></tr></table>

the same way as

<table border="1"><tr><td>foo</td></tr></table>

That is, they ignore the p markup in the sense that they don't apply the
normal default top and bottom margins. This is rather odd, especially
since they do leave some space between paragraphs, so they apparently
ignore just the top margin of the first paragraph and the bottom margin
of the last paragraph.


In Mozilla it varies between quirks and standards mode.

http://steve.pugh.net/test/test78q.html
http://steve.pugh.net/test/test78s.html

IE6 and Opera 7 - never displays the margin adjacent to the cell
top/bottom
Mozilla - displays the margins in standards mode but not quirks mode.

If the <p> elements have a border set then Opera behaves differently
again due to its implementation vertical margin collapsing.


Yes. This is all reverse engineering, to make tables in CSS-based browsers
look like they did in earlier browsers, even though the CSS and HTML spec
don't call for a special treatment of these cases. If you do explicitly
style the first or last block element in a table cell, Opera will honor
that. But by default the first top and last bottom margin will be zero.

--
Rijk van Geijtenbeek

The Web is a procrastination apparatus:
It can absorb as much time as is required to ensure that you
won't get any real work done. - J.Nielsen
Jul 20 '05 #7

P: n/a
Tim
On Thu, 22 Apr 2004 16:15:24 +0000 (UTC),
"Jukka K. Korpela" <jk******@cs.tut.fi> posted:
I just noticed that most browsers render

<table border="1"><tr><td><p>foo</p></td></tr></table>

the same way as

<table border="1"><tr><td>foo</td></tr></table>

That is, they ignore the p markup in the sense that they don't apply the
normal default top and bottom margins. This is rather odd, especially
since they do leave some space between paragraphs, so they apparently
ignore just the top margin of the first paragraph and the bottom margin
of the last paragraph.

Mozilla and Opera seem to do the same with <blockquote>, <form>, and
<ul>, whereas IE applies a _bottom_ margin to them when they appear as
the sole content of a cell.


I'd long ago noticed a related quirk with the way Opera includes Ps inside
DIVs (blank leading space above Ps, none after the last P). It always
emphasised the need, to me, to specify margins and padding for P elements
inside other elements with a set of conditional rules, else you get ugly
results (different browsers have different defaults).

The results of that sort of thing (below), are just peculiar in Opera:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">

<html>

<head>
<title>Paragraph spacing</title>
<style type="text/css">div, td {border: thin solid black;}</style>
</head>

<body>
<div><p>A paragraph.</p><p>A paragraph.</p></div>
<table><tr><td><p>A paragraph.</p><p>A paragraph.</p></td></tr></table>
</body>

</html>

--
If you insist on e-mailing me, use the reply-to address (it's real but
temporary). But please reply to the group, like you're supposed to.

This message was sent without a virus, please delete some files yourself.
Jul 20 '05 #8

P: n/a
Tim
On Thu, 22 Apr 2004 16:15:24 +0000 (UTC),
"Jukka K. Korpela" <jk******@cs.tut.fi> posted:
I just noticed that most browsers render

<table border="1"><tr><td><p>foo</p></td></tr></table>

the same way as

<table border="1"><tr><td>foo</td></tr></table>

That is, they ignore the p markup in the sense that they don't apply the
normal default top and bottom margins. This is rather odd, especially
since they do leave some space between paragraphs, so they apparently
ignore just the top margin of the first paragraph and the bottom margin
of the last paragraph.

Mozilla and Opera seem to do the same with <blockquote>, <form>, and
<ul>, whereas IE applies a _bottom_ margin to them when they appear as
the sole content of a cell.


I'd long ago noticed a related quirk with the way Opera includes Ps inside
DIVs (blank leading space above Ps, none after the last P). It always
emphasised the need, to me, to specify margins and padding for P elements
inside other elements with a set of conditional rules, else you get ugly
results (different browsers have different defaults).

The results of that sort of thing (below), are just peculiar in Opera:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">

<html>

<head>
<title>Paragraph spacing</title>
<style type="text/css">div, td {border: thin solid black;}</style>
</head>

<body>
<div><p>A paragraph.</p><p>A paragraph.</p></div>
<table><tr><td><p>A paragraph.</p><p>A paragraph.</p></td></tr></table>
</body>

</html>

--
If you insist on e-mailing me, use the reply-to address (it's real but
temporary). But please reply to the group, like you're supposed to.

This message was sent without a virus, please delete some files yourself.
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.