473,698 Members | 2,528 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4411
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.tu t.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.tu t.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.tu t.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.tu t.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.tu t.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>Paragrap h 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.tu t.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>Paragrap h 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
4247
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 like IE? The only thing that comes to mind is to use something like <h3 style="margin-top: 0"> in place of the first <h3>. But that seems very
2
5232
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 if I do not wrap the span tag inside a TR and TD, it is not properly placed in the table and the update does not work at all. However if I do place the span inside a TR and TD, the TR and TD which was supposed to go into the span is not becoming...
15
2091
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 ); } </script></head> <body onload="ready()"> <script type="text/javascript"> document.open();
14
2475
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 similar to <ul> and <li>. Of course i can eyeball and come up with a css, but want to be sure. ----------
3
2929
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. Does someone keep a list of workarounds in dealing with problems like these for the browsers that when listed in ranking order with respect to use, make up the 95-99% cumulatively used browsers?
6
2279
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. I assume Firefox does it correctly. Does this no-5%-bottom-margin happen because I have a specific paragraph bottom margin listed in the stylesheet after I have listed the 5% body margin?)
4
12761
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. Content is "pushed" from the back via some JS, for the only displayed portion of table. Once the user scrolls, JS updates visible cells with data. It's quite the philosophy behind GMaps and similars. So, the server says to JS "update this group...
4
3011
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 page should ignore all CSS properties that have been defined for it, and to adopt some form of browser default? Suppose I want to add a <tdelement to an *arbitrary* web page. I want this element to ignore any CSS directives that may already apply
2
4898
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 appreciate it if someone could explain 1- why MSIE 7 render this simple webpage so differently from Firefox
0
8680
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9030
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6528
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.