Closed Bug 398508 Opened 18 years ago Closed 17 years ago

Margin collapsing rule issue.

Categories

(Core :: Layout, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: BijuMailList, Unassigned)

Details

Attachments

(11 files)

Attached image fx_margin_issue.png
Margin collapsing rule issue. First case in the attached screenshot is of an HTML page with just a DIV and a H1 tag inside it. Background color the body is blue and for DIV is yellow. margin and padding for both is 0px. H1 tag has the standard margin-top 20px; (we do not need to set margin-top:20px for H1 just did it to compare with IE) Issues. 1. Why there is a blue space at the top of the page? (there is no other element before DIV, to show body's bg-color) 2. Why there is a scroll bar? (other than 100% sized DIV there is no other element in body, to exceed page size than the window size) In IE it looks fine, so is this IE violating CSS std or is it a mozilla bug!! I tried to put a <br> before H1, then the issue get solved but with a side effect of space for line break. IE ignore this line break also. adding <div style="height:1px"></div> before H1 almost solves the issue in firefox with 1 px offset. but now IE produce an extra space one line break. I have not tested in other browsers. The issue may also exist when the last element have a margin-bottom. We may also need testing for margin-left and margin-right also for padding in all those cases
Attached file test1.html
Attached file test2.html
Attached file test3.html
Attached file test4.html
Attached image ie_margin_ok.png
Attached file test5.html
with <div style="height:1px"></div> before H1
Work arround which is good for IE6 and Firefox is adding following div/br combination at the beginning and end. I also work for XHTML Strict mode <div class="size0"><br class="size0"/></div> <style> .size0 { height:0px; line-height:0px; font-size: 0px; padding:0px; margin:0px; } </style>
Attached file fx_issue_test1x.html
HTML Strict issue example
Attached image fx_issue_test1x.png
Thank you for reporting your issue. However, this is no bug. test1, test3: Here, the h1's top-margin collapses through the top of the div, so the body's background is shown and the element is shifted down by the size of the margin (thus you see a scrollbar). test2, test4, test5: Since there's an element between the div and the h1, the h1's marhin can't collapse. You can see the line created by br/1px-div and the top margin of h1. test6: top and bottom margins normally collapse. A workaround is to simply use padding. The size0 class seems rather hacky.
Status: NEW → RESOLVED
Closed: 17 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: