Answers for "how to avoid collapsing margins"

CSS
1

how to disable margin collapsing

/* This would create a small buffer between parent's and children elements's 
   margins. As such, margins won't collapse anymore.*/
.parentClass {
    padding: 0.05px;
}

/* Another solution would be to turn off margin-top on typography elements */
h1, h2, h3, p {
	margin-top: 0;  
}
Posted by: Guest on January-24-2022
1

css prevent margin collapsing

/* Some CSS Properties that prevent margin collapsing (each of them does) */

float: left;
float: right;

position: absolute;

display: inline-block;
display: flex;

overflow: hidden;
Posted by: Guest on October-13-2020

Browse Popular Code Answers by Language