![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have two div's that have float:left and a third that has clear:left and margin-top:10px. In IE 6 & 7, it displays as I intended, but in Safari, Firefox, Opera, it "ignores" the margin-top of the third div. If I put a margin-bottom:10px on one of the first two floated divs, I can get the desired effect, but am curious as to why it is not "working" in the non-ie browsers as initially stated? Sample: http://www.ericmmartin.com/code/css/margin-float.html |
#3
| |||
| |||
|
|
I have two div's that have float:left and a third that has clear:left and margin-top:10px. In IE 6 & 7, it displays as I intended, but in Safari, Firefox, Opera, it "ignores" the margin-top of the third div. If I put a margin-bottom:10px on one of the first two floated divs, I can get the desired effect, but am curious as to why it is not "working" in the non-ie browsers as initially stated? Sample: http://www.ericmmartin.com/code/css/margin-float.html |
#4
| ||||
| ||||
|
|
Eric Martin wrote: I have two div's that have float:left and a third that has clear:left and margin-top:10px. In IE 6 & 7, it displays as I intended, but in Safari, Firefox, Opera, it "ignores" the margin-top of the third div. If I put a margin-bottom:10px on one of the first two floated divs, I can get the desired effect, but am curious as to why it is not "working" in the non-ie browsers as initially stated? Sample: http://www.ericmmartin.com/code/css/margin-float.html Usenet is a great resource. You can learn a great deal, and get a lot of your questions answered here. That's part of why it's such a good idea to lurk in a newsgroup for a while, read through recent posts, and search the archives for discussions that may discuss the very thing you're looking for. You don't even have to post. |
|
As it happens, the thread "two-up" from your post[1] discusses the very thing which you're fighting against. See if this helps you: 91a468b2-c517-4276-9ef6-0e217e975... (AT) n20g2000hsh (DOT) googlegroups.com>. The thread is titled "Collapsing vertical margins on first block?" Look especially at Ben C's replies in that thread (and in general, too; he has a great awareness of CSS behavior). |
|
There is a phenomenon known as collapsing margins, which is what I think you're seeing. Your third div is not a float, although it appears it could be. If you make it a float (at least in your example), the top margin won't collapse and you'll see some space between divs. |
|
-- John Remembering the UIP:http://improve-usenet.org/ |
#5
| |||||
| |||||
|
|
Sample: http://www.ericmmartin.com/code/css/margin-float.html It is a difficult matter. You can read about collapsing margins if you want at http://www.w3.org/TR/CSS21/box.html#collapsing-margins> but it is not an easy read at all and there are quite some complications. |
|
You will see how the essentials appear differently in different browsers: http://netweaver.com.au/alt/martin.html In iCab (surprise?) and Mac IE5 (and I would bet quids on Win IE6 and a good few less quids on IE7) you will have the 10px white space of the body showing. But not on FF, Camino, Opera, Safari. I will be adding a few pages on this stuff at some stage to: http://netweaver.com.au/floatHouse/ |
|
But here are a couple of things to be considered: Let's try to be practical. You know about a bottom margin on a float - that is easiest way to go probably. But suppose this is not desirable for some reason. |
|
How about not clearing (because no need) the static div and inserting a clearing div between float and static. This div is a lowly nothing, it has no height and nothing much else to collapse or not collapse: http://netweaver.com.au/alt/martinPractical1.html This gets FF on board, Camino too! Mac IE and iCab were quite the tramp on standards already so this is no different for them. But Safari holds out, as does Opera. So stronger measures still are needed if a bottom margin on the float is not to your taste or practical. |
One thing I found interesting though, was|
Here is another couple to ponder: http://netweaver.com.au/alt/martinPractical2.html and http://netweaver.com.au/alt/martinPractica13.html The last is particularly interestig as it seems to trigger aquite a surprising thing in Opera: the mere mentioning in the css of a zero height for a clearing div is enough for Opera to suddenly think, ah, there is a 10px top border on a different static div |

#6
| |||
| |||
|
|
On Jan 24, 8:26 pm, dorayme <doraymeRidT... (AT) optusnet (DOT) com.au> wrote: [snip] Thanks again for the insight! |
#7
| |||
| |||
|
|
On Jan 24, 5:00 pm, John Hosking <J... (AT) DELETE (DOT) Hosking.name.INVALID [...] There is a phenomenon known as collapsing margins, which is what I think you're seeing. Your third div is not a float, although it appears it could be. If you make it a float (at least in your example), the top margin won't collapse and you'll see some space between divs. |
#8
| |||||
| |||||
|
|
In article ed3bc541-eb6d-4bdb-bb36-8b27c4f31bdb...oglegroups.com , Eric Martin <emartin24 (AT) gmail (DOT) com> wrote: I have two div's that have float:left and a third that has clear:left and margin-top:10px. In IE 6 & 7, it displays as I intended, but in Safari, Firefox, Opera, it "ignores" the margin-top of the third div. If I put a margin-bottom:10px on one of the first two floated divs, I can get the desired effect, but am curious as to why it is not "working" in the non-ie browsers as initially stated? Sample: http://www.ericmmartin.com/code/css/margin-float.html It is a difficult matter. You can read about collapsing margins if you want at http://www.w3.org/TR/CSS21/box.html#collapsing-margins> but it is not an easy read at all and there are quite some complications. You will see how the essentials appear differently in different browsers: http://netweaver.com.au/alt/martin.html In iCab (surprise?) and Mac IE5 (and I would bet quids on Win IE6 and a good few less quids on IE7) you will have the 10px white space of the body showing. |
|
But not on FF, Camino, Opera, Safari. |
|
How about not clearing (because no need) the static div and inserting a clearing div between float and static. This div is a lowly nothing, it has no height and nothing much else to collapse or not collapse: http://netweaver.com.au/alt/martinPractical1.html |
|
This gets FF on board, Camino too! Mac IE and iCab were quite the tramp on standards already so this is no different for them. But Safari holds out, as does Opera. |
|
So stronger measures still are needed if a bottom margin on the float is not to your taste or practical. Here is another couple to ponder: http://netweaver.com.au/alt/martinPractical2.html and http://netweaver.com.au/alt/martinPractica13.html The last is particularly interestig as it seems to trigger aquite a surprising thing in Opera: the mere mentioning in the css of a zero height for a clearing div is enough for Opera to suddenly think, ah, there is a 10px top border on a different static div |
#9
| |||
| |||
|
|
I have two div's that have float:left and a third that has clear:left and margin-top:10px. In IE 6 & 7, it displays as I intended, but in Safari, Firefox, Opera, it "ignores" the margin-top of the third div. If I put a margin-bottom:10px on one of the first two floated divs, I can get the desired effect, but am curious as to why it is not "working" in the non-ie browsers as initially stated? Sample: http://www.ericmmartin.com/code/css/margin-float.html |
#10
| |||
| |||
|
|
On 2008-01-25, dorayme <doraymeRidThis (AT) optusnet (DOT) com.au> wrote: In article ed3bc541-eb6d-4bdb-bb36-8b27c4f31bdb...oglegroups.com http://netweaver.com.au/alt/martinPractica13.html The last is particularly interesting as it seems to trigger quite a surprising thing in Opera: the mere mentioning in the css of a zero height for a clearing div is enough for Opera to suddenly think, ah, there is a 10px top border on a different static div That is very strange. If you set height: auto in Opera you get no gap, but height: 0px and you get the gap. There is no justification for that that I can see. |
![]() |
| Thread Tools | |
| Display Modes | |
| |