473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Default margins of elements inside table cells

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
8 4383
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
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
"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
"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Troy Parker | last post by:
Hello, When the example HTML below is viewed on IE 6, "Text" and "Heading" line up. On Mozilla 1.5, they don't; there's blank space above "Heading". What is the best way to make Mozilla look...
2
by: Falc2199 | last post by:
i all, I have an HTML table within which I have a span. When the user clicks a button I want to update the contents of this span with form elements table elements (TR,TD). The problem is that...
15
by: Christopher Benson-Manica | last post by:
When are named elements written with script accessible to script? <html><head><script type="text/javascript"> function ready() { alert( document.getElementsByName("div").length ); }...
14
by: Xah Lee | last post by:
is there somewhere i can find the default css for browsers? e.g. what's the usual rendering in terms of css for <p>, <ul> etc. in particular, right now i'm interested in creating a style...
3
by: Patient Guy | last post by:
For a long time, this page has been up and an embarrassment. http://tinyurl.com/ylcqum In Firefox, the table moves out of its parent container with the negative margin, but not in MSIE6. ...
6
by: Paul Wake | last post by:
Do paragraph bottom margins overrule body margins? (To explain what I mean, http://www.xmission.com/~wake/computerrules.html has 5% margins, including the bottom margin, in IE, but not in Firefox....
4
by: Claudio Calboni | last post by:
Hello folks, I'm having some performance issues with the client-side part of my application. Basically, it renders a huge HTML table (about 20'000 cells in my testing scenario), without content....
4
by: Duncan Jones | last post by:
I'm almost certain there is no easy answer to this question, but I'd thought I'd just check.... *Ignoring* for a second why I want to do this, is there any way to specify that an element in a...
2
by: GTalbot | last post by:
www.authoring.html] Hello fellow HTML and markup coder colleagues, Please visit this url: http://www.gtalbot.org/BrowserBugsSection/DefaultTopBottomMarginsForPargDisappear.html I would...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.