"
1- There is this huge vertical space between 2 DIVs at the top where there should be none
I am talking between:
class=âtop_txtâ
&
class=âbg_w_fotoâ
2- I have the 1st item in
class=âbg_w_fotoâ
as having margin-top: 150px
but it has NO margin from top spacing at all
I remove the HTML bracket tags. Sitepoint used to handle that. But I guess not anymore.
Anyway, they are removed and you can see the specified classes/DIVs now
Also the problem is obvious to see here:
What does that mean?
Again what I am looking for is to remove the white space between the top div that is one with class=âtop_txtâ
and the DIV below it that is one with class=âbg_w_fotoâ?
Specifically from your screen shot the blank white space with number 3 Should not be there.
Ha! That is weird!
1st, yes removing the margin-top: 150px; from that inner DIV does remove that blank space.
But that DIV is inside the DIV with class=âbg_w_fotoâ and that one has margin-top set to zero px and I thought that a DIV inside a DIV will have its margin push against that DIV and that the parent DIV does not have its margins affected by its chlid DIVs!!!
This is one more proof that CSS is crazy badly done. Because the margins of a child DIV should NOT affect the margins of the parent DIV. That is logical on any level of design.
Ok, so how do we then give the 1st DIV inside the parent DIV a margin-top of 150 px?
To be exact how do we have DIV containing line:
âAnoox Chat: Chat World Wide for Freeâ
to have margin-top of 150 px from the start of its parent DIV that is the one with class=âbg_w_fotoâ
Well, as i said, you can give the parent a 1-px padding, and then offset it with a margin-top,
Or you can add an empty element with a 1px height and no margin before the first <div> you want to margin.
Well I gave it a padding-top to get the result that we should have gotten from margin-top
Again this is one more example of CSS being full of crap
I tell you I will be real happy when we can hire a CSS expert so I do not have to mess with it again
There are some un-intuitive parts of css that could have been done better and margin-collapse is one of them but at the end of the day itâs pretty simple (not rocket science) if you have the time to learn the basics. You canât speak a language just by learning miscellaneous words! You have to know how to construct them into meaningful sentences and obey the rules of the language; itâs much the same with CSS.
I wrote this article on margin-collapse about 10 years ago and although its been updated by others since itâs still 99% my original words and explains the perils and pitfalls.
When I know it will not cause any problems, my first step is to put the parent in a new block formatting context. It became a habit with me long ago.
As was mentioned in the link that m_hutley provided in post#12.
Parent and first/last child
If there is no border, padding, inline part, block formatting context created, or clearance to separate the margin-top of a block from the margin-top of its first child block; or no border, padding, inline content, height, min-height, or max-height to separate the margin-bottom of a block from the margin-bottom of its last child, then those margins collapse. The collapsed margin ends up outside the parent.
But I stand with the fact that it makes NO Sense and in fact is totally wrong for the margin-top of a child DIV to affect the margin-top of the parent DIV.
But too busy with the chat release to argue this now
Perhaps I have had way too much exposure to SciFi for my own good, but one way I think of margins is theyâre like a âforce fieldâ that needs âmatterâ to push against. i.e. the two âforce fieldsâ do not have physical boundaries. Certain CSS can give âboundariesâ where there would otherwise not be and the margin will work as expected.