A single margin may occasionally replace two margins.
Sometimes, an element’s top and bottom margins are combined into a single margin that equals the bigger of the two margins.
The left and right margins are not where this occurs! Just the upper and lower margins!
Take a look at this instance:
Demonstration of margin collapse:
h1 {
margin: 0 0 50px 0;
}
h2 {
margin: 20px 0 0 0;
}
The <h1> element in the example above has a 50px bottom margin, and the <h2> element has a 20px top margin.
The vertical margin between the <h1> and the <h2> should be a total of 70px (50px + 20px), according to common sense. However, the real margin is 50px as a result of margin collapse.
Property | Description |
---|---|
margin | A shorthand property for setting all the margin properties in one declaration |
margin-bottom | Sets the bottom margin of an element |
margin-left | Sets the left margin of an element |
margin-right | Sets the right margin of an element |
margin-top | Sets the top margin of an element |
CodingAsk.com is designed for learning and practice. Examples may be made simpler to aid understanding. Tutorials, references, and examples are regularly checked for mistakes, but we cannot guarantee complete accuracy. By using CodingAsk.com, you agree to our terms of use, cookie, and privacy policy.
Copyright 2010-2024 by Refsnes Data. All Rights Reserved.