473,382 Members | 1,365 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,382 software developers and data experts.

Effect of border/padding and nested margins on outer block layout

I just noticed an unintuitive aspect of how nested blocks are positioned
under a specific set of conditions, and although this is ostensibly
correct behavior (unless Firefox, Safari, and Opera are all three
simultaneously wrong about this particular quirk), I'm having a hard
time figuring out the underlying premise of this behavior.

Essentially, when a nested block has a non-zero top margin greater than
that of its containing block, the containing block is positioned in an
unexpected (to the naive developer) manner when both its border-top and
padding-top properties are zero... but a picture is worth a thousand
words, so here is an interactive example of the phenomenon:

http://markshroyer.com/files/css-example.html

I get the feeling that there's some fundamental concept I'm missing
here, but I'm not having much luck searching for the answer on my own...
any hints?

Thanks!
Mark

--
Mark Shroyer
http://markshroyer.com/contact/
Jun 27 '08 #1
14 1687
Mark Shroyer wrote:
I just noticed an unintuitive aspect of how nested blocks are positioned
under a specific set of conditions, and although this is ostensibly
correct behavior (unless Firefox, Safari, and Opera are all three
simultaneously wrong about this particular quirk), I'm having a hard
time figuring out the underlying premise of this behavior.

Essentially, when a nested block has a non-zero top margin greater than
that of its containing block, the containing block is positioned in an
unexpected (to the naive developer) manner when both its border-top and
padding-top properties are zero... but a picture is worth a thousand
words, so here is an interactive example of the phenomenon:

http://markshroyer.com/files/css-example.html

I get the feeling that there's some fundamental concept I'm missing
here, but I'm not having much luck searching for the answer on my own...
any hints?
_Collapsing Margins_
Most people think of margin collapsing happening when one block level
element follows another. However margins collapse whenever one margin
comes into contact with an adjacent margin. This means that margins can
also collapse when one element is contained within another.

To Prevent Adjacent Margins from Collapsing one can make them no longer
Adjacent by either; adding a border or adding some padding.

Read up on it in the CSS 2.1 Specifications.
Search the web for documents describing it.

--
Gus
Jun 27 '08 #2
In article <us*******************************@snap.homestarmy .net>,
Mark Shroyer <us*********@markshroyer.comwrote:
I just noticed an unintuitive aspect of how nested blocks are positioned
under a specific set of conditions, and although this is ostensibly
correct behavior (unless Firefox, Safari, and Opera are all three
simultaneously wrong about this particular quirk), I'm having a hard
time figuring out the underlying premise of this behavior.

Essentially, when a nested block has a non-zero top margin greater than
that of its containing block, the containing block is positioned in an
unexpected (to the naive developer) manner when both its border-top and
padding-top properties are zero... but a picture is worth a thousand
words, so here is an interactive example of the phenomenon:

http://markshroyer.com/files/css-example.html

I get the feeling that there's some fundamental concept I'm missing
here, but I'm not having much luck searching for the answer on my own...
any hints?
Best I can do for the moment:

<http://netweaver.com.au/alt/shroyer.html>

--
dorayme
Jun 27 '08 #3
On 2008-04-16, dorayme <do************@optusnet.com.auwrote:
In article <us*******************************@snap.homestarmy .net>,
Mark Shroyer <us*********@markshroyer.comwrote:
>I just noticed an unintuitive aspect of how nested blocks are positioned
under a specific set of conditions, and although this is ostensibly
correct behavior (unless Firefox, Safari, and Opera are all three
simultaneously wrong about this particular quirk), I'm having a hard
time figuring out the underlying premise of this behavior.

Essentially, when a nested block has a non-zero top margin greater than
that of its containing block, the containing block is positioned in an
unexpected (to the naive developer) manner when both its border-top and
padding-top properties are zero... but a picture is worth a thousand
words, so here is an interactive example of the phenomenon:

http://markshroyer.com/files/css-example.html

I get the feeling that there's some fundamental concept I'm missing
here, but I'm not having much luck searching for the answer on my own...
any hints?

Best I can do for the moment:

<http://netweaver.com.au/alt/shroyer.html>
Good explanation. I think the main point to note here is that when two
box's top margins collapse, it also follows that the top edges of those
two boxes end up in the same place.

Yellow's top margin (of 0) collapses with red's. The result is 16px.
That needs to be between the top of red and the bottom of blue since
it's red that wants this top margin.

But now since the top of yellow has to be aligned with the top of red,
yellow has to move down by 16px.
Jun 27 '08 #4
In article <sl*********************@bowser.marioworld>,
Ben C <sp******@spam.eggswrote:
On 2008-04-16, dorayme <do************@optusnet.com.auwrote:
In article <us*******************************@snap.homestarmy .net>,
Mark Shroyer <us*********@markshroyer.comwrote:
I just noticed an unintuitive aspect of how nested blocks are positioned
under a specific set of conditions, and although this is ostensibly
correct behavior (unless Firefox, Safari, and Opera are all three
simultaneously wrong about this particular quirk), I'm having a hard
time figuring out the underlying premise of this behavior.

Essentially, when a nested block has a non-zero top margin greater than
that of its containing block, the containing block is positioned in an
unexpected (to the naive developer) manner when both its border-top and
padding-top properties are zero... but a picture is worth a thousand
words, so here is an interactive example of the phenomenon:

http://markshroyer.com/files/css-example.html

I get the feeling that there's some fundamental concept I'm missing
here, but I'm not having much luck searching for the answer on my own...
any hints?
Best I can do for the moment:

<http://netweaver.com.au/alt/shroyer.html>

Good explanation. I think the main point to note here is that when two
box's top margins collapse, it also follows that the top edges of those
two boxes end up in the same place.

Yellow's top margin (of 0) collapses with red's. The result is 16px.
That needs to be between the top of red and the bottom of blue since
it's red that wants this top margin.

But now since the top of yellow has to be aligned with the top of red,
yellow has to move down by 16px.
It is indeed interesting quite how one can look at these things. I try
to think of some way that I will actually be able to remember. Others
will have more technically looking explanations (things that seem closer
to CSS 2.1 specs). Love these questions because they force us to think
about a few things! <g>

--
dorayme
Jun 27 '08 #5
In article <us*******************************@snap.homestarmy .net>,
Mark Shroyer <us*********@markshroyer.comwrote:
http://markshroyer.com/files/css-example.html
I meant to mention that this was a very nicely presented question, Mark!
In Safari, the javascript feature worked one way but not the other. In
FF, both ways worked. (You could go from borderless to bordered example,
but not vice versa. Refresh page got the reverse better!) Nice touch but
also an illustration of the downside of js across all browsers and
platforms.

Must update to Safari 3 soon!

--
dorayme
Jun 27 '08 #6
dorayme wrote:
In article <sl*********************@bowser.marioworld>,
Ben C <sp******@spam.eggswrote:
>On 2008-04-16, dorayme <do************@optusnet.com.auwrote:
>>In article <us*******************************@snap.homestarmy .net>,
Mark Shroyer <us*********@markshroyer.comwrote:

I just noticed an unintuitive aspect of how nested blocks are positioned
under a specific set of conditions, and although this is ostensibly
correct behavior (unless Firefox, Safari, and Opera are all three
simultaneously wrong about this particular quirk), I'm having a hard
time figuring out the underlying premise of this behavior.

Essentially, when a nested block has a non-zero top margin greater than
that of its containing block, the containing block is positioned in an
unexpected (to the naive developer) manner when both its border-top and
padding-top properties are zero... but a picture is worth a thousand
words, so here is an interactive example of the phenomenon:

http://markshroyer.com/files/css-example.html

I get the feeling that there's some fundamental concept I'm missing
here, but I'm not having much luck searching for the answer on my own...
any hints?

Best I can do for the moment:

<http://netweaver.com.au/alt/shroyer.html>
Good explanation. I think the main point to note here is that when two
box's top margins collapse, it also follows that the top edges of those
two boxes end up in the same place.

Yellow's top margin (of 0) collapses with red's. The result is 16px.
That needs to be between the top of red and the bottom of blue since
it's red that wants this top margin.

But now since the top of yellow has to be aligned with the top of red,
yellow has to move down by 16px.

It is indeed interesting quite how one can look at these things. I try
to think of some way that I will actually be able to remember. Others
will have more technically looking explanations (things that seem closer
to CSS 2.1 specs). Love these questions because they force us to think
about a few things! <g>
Of course there is also the fact that blue's bottom margin is adjacent
with your "family unit of yellow parent with red child" left to also be
considered.

Since blue's bottom margin is zero and the "family unit's" top margin is
16px, it collapses to 16px. If blue's bottom margin were greater than
the "family unit's" top margin (>16px), the result would be collapsed to
blue's greater bottom margin value.

--
Gus
Jun 27 '08 #7
In article <do**********************************@web.aioe.org >,
dorayme <do************@optusnet.com.auwrote:
In article <us*******************************@snap.homestarmy .net>,
Mark Shroyer <us*********@markshroyer.comwrote:
I just noticed an unintuitive aspect of how nested blocks are positioned
under a specific set of conditions, and although this is ostensibly
correct behavior (unless Firefox, Safari, and Opera are all three
simultaneously wrong about this particular quirk), I'm having a hard
time figuring out the underlying premise of this behavior.

Essentially, when a nested block has a non-zero top margin greater than
that of its containing block, the containing block is positioned in an
unexpected (to the naive developer) manner when both its border-top and
padding-top properties are zero... but a picture is worth a thousand
words, so here is an interactive example of the phenomenon:

http://markshroyer.com/files/css-example.html

I get the feeling that there's some fundamental concept I'm missing
here, but I'm not having much luck searching for the answer on my own...
any hints?

Best I can do for the moment:

<http://netweaver.com.au/alt/shroyer.html>
Great explanation, thanks!

--
Mark Shroyer
http://markshroyer.com/contact/
Jun 27 '08 #8
In article <Io******************************@golden.net>,
Gus Richter <gu********@netscape.netwrote:
dorayme wrote:
In article <sl*********************@bowser.marioworld>,
Ben C <sp******@spam.eggswrote:
On 2008-04-16, dorayme <do************@optusnet.com.auwrote:
In article <us*******************************@snap.homestarmy .net>,
Mark Shroyer <us*********@markshroyer.comwrote:

I just noticed an unintuitive aspect of how nested blocks are positioned
...example of the phenomenon:

http://markshroyer.com/files/css-example.html

I get the feeling that there's some fundamental concept I'm missing
here, but I'm not having much luck searching for the answer on my own...

any hints?

Best I can do for the moment:

<http://netweaver.com.au/alt/shroyer.html>
Good explanation. I think the main point to note here is that when two
box's top margins collapse, it also follows that the top edges of those
two boxes end up in the same place.

Yellow's top margin (of 0) collapses with red's. The result is 16px.
That needs to be between the top of red and the bottom of blue since
it's red that wants this top margin.

But now since the top of yellow has to be aligned with the top of red,
yellow has to move down by 16px.
It is indeed interesting quite how one can look at these things.
....
Of course there is also the fact that blue's bottom margin is adjacent
with your "family unit of yellow parent with red child" left to also be
considered.

Since blue's bottom margin is zero and the "family unit's" top margin is
16px, it collapses to 16px. If blue's bottom margin were greater than
the "family unit's" top margin (>16px), the result would be collapsed to
blue's greater bottom margin value.
Indeed. There are the internal family problems to be sorted out and then
the *various ones* to do with relations to strangers. It is always a
toss up as to which are the most complex.

(Did I ever tell you, Gus, about the bloke who put up a sign on his
front door saying, "Everyone welcome - except family members")

--
dorayme
Jun 27 '08 #9
dorayme wrote:
In article <Io******************************@golden.net>,
Gus Richter <gu********@netscape.netwrote:
>dorayme wrote:
>>In article <sl*********************@bowser.marioworld>,
Ben C <sp******@spam.eggswrote:

On 2008-04-16, dorayme <do************@optusnet.com.auwrote:
In article <us*******************************@snap.homestarmy .net>,
Mark Shroyer <us*********@markshroyer.comwrote:
>
>I just noticed an unintuitive aspect of how nested blocks are positioned
>...example of the phenomenon:
>>
>http://markshroyer.com/files/css-example.html
>>
>I get the feeling that there's some fundamental concept I'm missing
>here, but I'm not having much luck searching for the answer on my own...
>>
>any hints?
>>
Best I can do for the moment:
>
<http://netweaver.com.au/alt/shroyer.html>
Good explanation. I think the main point to note here is that when two
box's top margins collapse, it also follows that the top edges of those
two boxes end up in the same place.

Yellow's top margin (of 0) collapses with red's. The result is 16px.
That needs to be between the top of red and the bottom of blue since
it's red that wants this top margin.

But now since the top of yellow has to be aligned with the top of red,
yellow has to move down by 16px.
It is indeed interesting quite how one can look at these things.
...
>Of course there is also the fact that blue's bottom margin is adjacent
with your "family unit of yellow parent with red child" left to also be
considered.

Since blue's bottom margin is zero and the "family unit's" top margin is
16px, it collapses to 16px. If blue's bottom margin were greater than
the "family unit's" top margin (>16px), the result would be collapsed to
blue's greater bottom margin value.

Indeed. There are the internal family problems to be sorted out and then
the *various ones* to do with relations to strangers. It is always a
toss up as to which are the most complex.
Actually I don't much care for this "family" thing.
The fact is that there are three adjacent margins - three margins in
contact with each other - they all collapse to that of the largest one.
(Did I ever tell you, Gus, about the bloke who put up a sign on his
front door saying, "Everyone welcome - except family members")
Bloke? What's a bloke? Chap? What's a chap?
I think that for non-british types (i.e. North American and god knows
where else) "fellow" may be used, although I prefer "guy".

Do you people down under also use torch for flashlight and knock up for
wake up?

--
Gus
Jun 27 '08 #10
In article <7M******************************@golden.net>,
Gus Richter <gu********@netscape.netwrote:
Actually I don't much care for this "family" thing.
The fact is that there are three adjacent margins - three margins in
contact with each other - they all collapse to that of the largest one.
Fair enough. All clear and simple then, there are 3 adjacent margins and
they all collapse to the largest one and this explains everything
including the meaning of the universe.

And now to other interesting matters:
(Did I ever tell you, Gus, about the bloke who ...

Bloke? What's a bloke? Chap? What's a chap?
I think that for non-british types (i.e. North American and god knows
where else) "fellow" may be used, although I prefer "guy".
New Zealanders use "Joker". This joker did this and that joker came
along and did that.... At least my NZ friends talk like this.
Do you people down under also use torch for flashlight
I use "torch". I think most Australians do too. Our torches are reliable
you see and don't go on and off all the time. You know what I mean,
mate? Beaut!
>and knock up for wake up?
No, "knock up" has a different meaning in these parts. When a bloke
knocks up a sheila, she wakes up one day with a bun in the oven. Know
what I mean?

--
dorayme
Jun 27 '08 #11
rf
dorayme <do************@optusnet.com.auwrote in news:doraymeRidThis-
7B*******************@web.aioe.org:
In article <7M******************************@golden.net>,
Gus Richter <gu********@netscape.netwrote:
>Do you people down under also use torch for flashlight

I use "torch". I think most Australians do too. Our torches are reliable
you see and don't go on and off all the time. You know what I mean,
mate? Beaut!
Besides, imagine using a torch that had "flash" in its name :-)

--
Richard
Killing all threads involving google groups
The Usenet Improvement Project: http://improve-usenet.org
Jun 27 '08 #12
dorayme wrote:
And now to other interesting matters:
>>(Did I ever tell you, Gus, about the bloke who ...
Bloke? What's a bloke? Chap? What's a chap?
I think that for non-british types (i.e. North American and god knows
where else) "fellow" may be used, although I prefer "guy".

New Zealanders use "Joker". This joker did this and that joker came
along and did that.... At least my NZ friends talk like this.
>Do you people down under also use torch for flashlight

I use "torch". I think most Australians do too. Our torches are reliable
you see and don't go on and off all the time. You know what I mean,
mate? Beaut!
>and knock up for wake up?

No, "knock up" has a different meaning in these parts. When a bloke
knocks up a sheila, she wakes up one day with a bun in the oven. Know
what I mean?
This joker, this guy, this old fart, etc. are lead ins to jokes, true.

Re. the last; understood all, even the sheila, after all I know that
Waltzing Matilda has nothing to do with any girl or about dancing.

Funny this linguistic thing, gday mate.

--
Gus

Jun 27 '08 #13
rf
Gus Richter <gu********@netscape.netwrote in
news:z_******************************@golden.net:
Funny this linguistic thing, gday mate.
G'day is usually used when greeting a bloke, not when wandering off. Hooroo
is more appropriate then.

--
Richard
Killing all threads involving google groups
The Usenet Improvement Project: http://improve-usenet.org
Jun 27 '08 #14
rf wrote:
Gus Richter <gu********@netscape.netwrote in
news:z_******************************@golden.net:
>Funny this linguistic thing, gday mate.

G'day is usually used when greeting a bloke, not when wandering off. Hooroo
is more appropriate then.
Thanks for that and hooroo to this thread.

--
Gus

Jun 27 '08 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Red | last post by:
This is apparently an ie display bug, I can't seem to figure out which ie bug this is. a 3 sided border is created by wrapping the 'inner' box in the 'middle' box and padding the 'middle' box...
0
by: Red | last post by:
See http://reenie.org/test9.php There are two examples each with three nested divs. The only difference between the two is that the first example has no padding in the inner div, the second...
2
by: Florian Brucker | last post by:
I got a problem with code looking like that: <div class="outer"> <div class="inner"> Sample text </div> </div> The outer DIV has margin/padding=0, the inner DIV has a margin (all 4 sides)....
7
by: Bob Bedford | last post by:
I've an image in a cell of a table. I've this CSS: ..dbtable{ width: 600px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; border-collapse: collapse; border: 1px solid #000000;
11
by: muraii | last post by:
Hi all, I've trolled through Google, a little of evolt, css-discuss archives, and sent the list a request, all to no avail. I consulted positioniseverything.net and quirksmode.org. The issue I...
6
by: Gordowey | last post by:
Where can I find this DIV effect. go to: http://www.amazon.com Put mouse over the text "See All 32 Product Categories" (Top-Middle)..it will open a window with a cool effect... does anyone...
6
by: Hacking Bear | last post by:
Hi, I still don't quite fully understand how to handle mixing border/margin pixel width with percentage width. In the example below, I want to place side-by-side two DIV boxes inside a box....
12
by: Amer Neely | last post by:
I'm trying to nail down a 3-column layout but there is a slight discrepancy in how IE 6 and Seamonkey renders a border. View my attempt at http://www.softouch.on.ca/scratch/3-columns.html The...
10
by: crazeway | last post by:
The top margin of a nested div (#main) is pulling down its containing div (#middle) along with the 2 floated divs flanking it. This problem corrects itself and gives me the desired effect if I add a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.