If I have a child element with some margin established, its parent won’t return its actual height ( wont’t count the child’s margin, I mean) when using the command .outerHeight(), unless I establish either (not all) of the following properties to the parent div:
Why is that? Which of these properties should I use (..and why ‘-‘)? Should I do something different? Ty in advance. Here’s the code:
< !DOCTYPE HTML>
So, if I put either of those css properties i talked about earlier(in #login selector) it would work out fine , but not sure why ‘-‘. In this example the form element(.form selector) has a margin that causes its div parent not to calculate its height right.
That’s correct behavior. And for the record, padding-top would also work. The child’s margin extends outside of the parent unless the parent is given a new block formatting context. You’ve hit most of the ways to do that. I personally would use the overflow: hidden;
Ty you all guys, think I have finally figured it out.
I tried checking the website you suggested wolfcry911, but couldn’t grasp much from there, so i tried searching some other sites (many.. so can’t ref them all here) besides some of the css official documentation (http://www.w3.org/TR/CSS2/box.html) (http://www.w3.org/TR/CSS2/visuren.html) and the conclusion I had figured out (I think) is:
Since I dont include padding, border, or anything else before the form’s margin, **its margin will collapse with the #login’s margin**, so if I had included a “padding: 1px” property in #login, it would also work out, since the collapse wouldn’t be allowed anymore =]. That is also the reason why the ‘border’ property I mentioned earlier would also work.
As for the display properties, it’s as wolfcry911 said: they create a new block formatting context, **which doesn’t allow margin collapsing either**, and that’s why it works: the form’s margin remains inside the #login block, instead of out of it, collapsed with its own margin, so the outerHeight can be calculated as I expected =]
In the end, it was all about “margin collapsing” properties, which by this day I’d never heard about ‘-‘
Ty again guys o/
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic.
*May or may not contain any actual "CSS" or "Tricks".