Em vs Px and cross browser compatibility

后端 未结 4 1002
逝去的感伤
逝去的感伤 2021-02-07 19:07

I\'m a CSS newbie and was wondering if there is a benefit using em instead of px when it comes the cross browser compatibility of my CSS.

4条回答
  •  太阳男子
    2021-02-07 20:04

    I believe some of the guidelines I learned when first beginning Web work have fallen by the wayside and the recommendaion against sizing fonts by px is one of them. The reason is simple - all contemporary browsers now graphically zoom entire pages very cleanly and thus text sizing as a feature of the browser is moot.

    The text enlargement problem only exists with IE6 (you can zoom IE8). IE6 is now under 10% share globally. Those who are "hard of sight" make up about 2% of the US population. That means trying to deal with IE6 benefits 0.2% of users in the US. If there were a browser out there with 0.2% share, we would all ignore it.

    The benefit of ignoring "scalable" font sizing in favor of px is very high because it is simpler, both to implement and to understand. It is less likely to be affected by mysteries of the cascade, for one thing. It is especially useful in situations where height must be precisely controlled, such as in a menu bar.

    I have only recently started removing em and % from sites I'm building in favor of px, so there might be gotchas I haven't hit. So far, I find the result encouraging.

    I would thus recommend px, not only for beginners but in general.

提交回复
热议问题