So essentially does margin collapsing occur when you don’t set any margin or padding or border to a given div element?
So essentially does margin collapsing occur when you don’t set any margin or padding
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No. When you have two adjacent vertical margins, the greater of the two is used and the other is ignored.
So, for instance, if you have two block-display elements, A, followed by B beneath it, and A has a bottom-margin of 3em, while B has a top-margin of 2em, then the distance between them will be 3em.
If you set a border or padding, this prevents the collapsing from occurring. In the above example, the distance between the two elements will then be 5em.
If you don’t set any margins, then there won’t be any margins to collapse. It has nothing whatsoever to do with the element type in use – it is applicable to all element types, not just
<div>elements.Read the CSS 2.1 specification for more details.