Common problem with CSS margin
I do not know how common this problem is for other users, but for me, it's pretty common and I have no real idea why it is happening.
But let me explain the symptoms. :)
When ever I do a layout using css and divs I many times end up with some place wh开发者_如何学JAVAere margin just stops working as it should. It could be that it adds space to the left and right but usually not top and down.
Other times a margin on top of a div results in an unwanted space further down on the page.
Anyone with experience of this problem? And what am I probably doing wrong?
All divs are of course properly closed, so it isn't that obvious. And I know, I know, it's super hard to answer width no real example. I'm just throwing out a rope gere and hoping for a savior. Thanks!
I think the problem is with float
and margin
together. margin will not apply for example if you have a div
with float:right
and another div without float after it ! no margin between these two elements will be applied. unless you set a float for second element too !
but remember in these situations, margin
applied for contents of both elements. not for borders. content will align correctly but borders not!
this is a common problem that we can call it as a BROWSER BUG!
If you have eny specific problem let us to know.
if u can post some code..it will be helpful. see these sites and try to see where ur going wrong.. http://www.w3.org/TR/CSS21/box.html
http://www.w3schools.com/css/css_boxmodel.asp
精彩评论