I have a header div as the first element in my wrapper div, but when I add a top margin to a h1 inside the header div it pushes the entire header div down. I realize this ha
This are some of the ways to avoid margin collapsing between parent-child elements. Use the one that fits better with the rest of your styling:
display
to other than block
.float
to other than none
.padding
. For example if you had margin-top: 10px
, replace with padding-top: 10px;
.position
(absolute
or relative
) with attributes top
, bottom
, etc. For example if you had margin-top: 10px
, replace with position: relative; top: 10px;
.padding
or a border
in the side where the margins are collapsing, to the parent element. The border can be 1px and transparent.overflow
to other than visible
to the parent element.