How to convert margins and padding from px to em?

Please tell me whether I understand the rules of recalculation of the margins and padding from px to em? If the element is set to the font size of that margin and padding are divided on it, but if not specified then divided by the font of the parent? Tried by the method of Eaton markota, i.e. margin divided by the font size of the parent, and padding divided by the font size of the element itself, so it is not always such a division of the... Tell me how all the same right?
July 8th 19 at 11:34
2 answers
July 8th 19 at 11:36
Solution
Margin and padding in em are always calculated from the font size of the element by the formula:

margin(em) = margin(px) / font-size(px)

where the font-size(px)computed value of the font size. Although the font size can be specified in any units or can be inherited from any parent.

When the chain of parents is specified the font size in em, it is very easy to get confused with all these conversions. Guided by the calculated value, which you can see in the developer tools in the browser (see right column).

a23370385b8b4a189b2e98eb727e3fb2.png
Thank you very much for the answer. For such calculations I use Firefox'om there I like the tab "calculated". Thanks again!!! - Lonie_DAmore commented on July 8th 19 at 11:39
Will see What units it is preferable to use the adaptive layout CSS 3? - fleta.McLaughl commented on July 8th 19 at 11:42
: Thank you, very useful. It's great that people are not too lazy to write everything in detail! - Lonie_DAmore commented on July 8th 19 at 11:45
July 8th 19 at 11:38
Easier to convert to rem
1rem = 16px
I really like Rem, it is simpler and less confusion, but it is not always flexible. I mainly use it when you need similar elements to specify a relative size, but parents are different. - Lonie_DAmore commented on July 8th 19 at 11:41

Find more questions by tags Adaptive design