![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| ||||
| ||||
|
|
I noticed something that does not make sense to me. I do not read this NG regularly, so I hope I am not asking something that has been answered before. Anyway... The top value of a DIV is affected by the following conditions: * child of relatively positioned BODY (not static, not absolute) * BODY has a PRE as a child * DIV appears as a child of BODY before any other text node or any other element having border, height or width. * no border on BODY Noticed in these browsers: IE8, Chrome 2, Safari 4, Firefox 3.5, Seamonkey 1.1, Opera 10. The result is that the testNode DIV is offset by the font size of the PRE element. http://dhtmlkitchen.com/ape/adhoctest/css/bodynows.html #testNode is, from viewport edge, flush left and offset from the top by the PRE's font size. I expected #testNode to be at 0, 0. Why do the browsers position #testNode from the top, based on the font-size of the PRE element? |
|
Adding a text node in BODY or a div with height before #testNode will also cause testNode to be at 0,0. |
|
Why is #testNode's top offset by the PRE's fontSize when BODY has position: relative? |
|
Why does adding a border to BODY change that? |
#3
| |||
| |||
|
|
On 2009-09-19, Garrett Smith <dhtmlkitchen (AT) gmail (DOT) com> wrote: I noticed something that does not make sense to me. I do not read this NG regularly, so I hope I am not asking something that has been answered before. Anyway... The top value of a DIV is affected by the following conditions: |
|
Why do the browsers position #testNode from the top, based on the font-size of the PRE element? It looks like Firefox (and Opera) are setting top and bottom margins of about 1em on pre in the default stylesheet, which is a reasonable thing to do. |
|
A box's top margin only collapses with the top margin of its child if it doesn't have a border. It's all in 8.3.1 of the CSS 2.1 spec (and is the second hardest thing to understand in CSS). |
#4
| |||
| |||
|
|
Why does adding a border to BODY change that? A box's top margin only collapses with the top margin of its child if it doesn't have a border. It's all in 8.3.1 of the CSS 2.1 spec (and is the second hardest thing to understand in CSS). |
#5
| |||
| |||
|
|
Ben C wrote: On 2009-09-19, Garrett Smith <dhtmlkitchen (AT) gmail (DOT) com> wrote: I noticed something that does not make sense to me. I do not read this NG regularly, so I hope I am not asking something that has been answered before. Anyway... The top value of a DIV is affected by the following conditions: [snip] Why do the browsers position #testNode from the top, based on the font-size of the PRE element? It looks like Firefox (and Opera) are setting top and bottom margins of about 1em on pre in the default stylesheet, which is a reasonable thing to do. And Chrome and probably IE8 and possibly others. [snip] A box's top margin only collapses with the top margin of its child if it doesn't have a border. It's all in 8.3.1 of the CSS 2.1 spec (and is the second hardest thing to understand in CSS). Thank you for clearing up my confusion with the detailed explanation. But what is the #1 hardest thing to understand in CSS? |
#6
| |||
| |||
|
|
Ben C wrote: On 2009-09-19, Garrett Smith <dhtmlkitchen (AT) gmail (DOT) com> wrote: I noticed something that does not make sense to me. I do not read this NG regularly, so I hope I am not asking something that has been answered before. Anyway... The top value of a DIV is affected by the following conditions: [snip] Why do the browsers position #testNode from the top, based on the font-size of the PRE element? It looks like Firefox (and Opera) are setting top and bottom margins of about 1em on pre in the default stylesheet, which is a reasonable thing to do. And Chrome and probably IE8 and possibly others. |
|
[snip] A box's top margin only collapses with the top margin of its child if it doesn't have a border. It's all in 8.3.1 of the CSS 2.1 spec (and is the second hardest thing to understand in CSS). Thank you for clearing up my confusion with the detailed explanation. But what is the #1 hardest thing to understand in CSS? |
#7
| |||
| |||
|
|
In article <slrnhbbp85.33j.spamspam (AT) bowser (DOT) marioworld>, Ben C <spamspam (AT) spam (DOT) eggs> wrote: Why does adding a border to BODY change that? A box's top margin only collapses with the top margin of its child if it doesn't have a border. It's all in 8.3.1 of the CSS 2.1 spec (and is the second hardest thing to understand in CSS). Just a small note on this for now. I have noticed that a non-zero padding on a parent can also make the top margin of a child spring to life. http://dorayme.netweaver.com.au/alt/absolutely_one.html |
![]() |
| Thread Tools | |
| Display Modes | |
| |