I created a small test web page, and the line heights are different, although they use the same CSS style. This becomes most visible when using Chrome to highlight the usage of the .instruction class. It seems as if the total margins between two lines are cut in half for items directly right to the bracket.
The CSS file is available here.
Keeping in mind that all lines use the exact same .instruction class CSS style:
.instruction {
max-width: 48ch;
display: flex;
flex-direction: row;
margin: 0.2em 0em;
vertical-align: middle;
}
Any help would be greatly appreciated!
2
Answers
There might be 2 reasons why it is happening:
Reason 1
em
unit is relative to the font size of the parent element. linkYour margin size is differing because the font size of the parent element is different.
If you want to use consistent margin, either use absolute values such as
margin: 5px 0;
or relative unitrem
.rem
is relative to the font size of the the root element, (default 16px).Reason 2
Margin Collapsing
You can read more about margin collapsing and when it happens on this page.
How to prevent margin collapsing?
One easy hack is to use
display:flex;
ordisplay:grid;
.SideNote:
flex-direction: row;
is a default value, so you don’t have to define it. linkTry using px or rem while giving margins.