kayut Posted April 17, 2015 Share Posted April 17, 2015 Hi, Consider a web page with two adjacent paragraphs: <p> first paragraph</p><p> second paragraph</p> With this CSS code applied to a web page: p { background-color: red; margin-top: 50px; margin-bottom: 50px;} What will be the distance between the two red rectangles displayed for the background color of these paragraphs? Answer: I thought it should be 100px but NO, the distance between two paragraphs would be only 50px. Can some one please explain WHY?? Tahnks Link to comment Share on other sites More sharing options...
davej Posted April 17, 2015 Share Posted April 17, 2015 That seems pretty simple. Do you logically want to measure margin to the edge of another margin, or the the edge of another element? Link to comment Share on other sites More sharing options...
kayut Posted April 17, 2015 Author Share Posted April 17, 2015 I just want to understand it. I mean if the first <p> element 50px margin-bottom and the second <p> element 50px margin-top has then the distance between two paragraphs should be 100px. Why is it still 50px ???? Link to comment Share on other sites More sharing options...
davej Posted April 17, 2015 Share Posted April 17, 2015 Margin: the distance to the edge of another ELEMENT. NOT the distance to the edge of another MARGIN. 1 Link to comment Share on other sites More sharing options...
Ingolme Posted April 17, 2015 Share Posted April 17, 2015 It's something called collapsing margins. When two elements' margins are adjacent, the larger of the two margins is used while the other is ignored. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now