Fallback for CSS attributes without unit

后端 未结 2 1808
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 10:23

Consider a scenario where CSS attribute is missing the unit (px, em, pt, %):


    
2条回答
  •  青春惊慌失措
    2020-11-30 11:11

    1. px is the most common unit used, so generally browsers use their "common sense" and use px as it is the most used unit in web designs if no unit is specified.
    2. No there is no such rule. Browsers just use the most used unit in designs.
    3. The ideal behaviour should be to use px and move on without ignoring other styles, but there is no such rule so when you see different browsers different things they are actually implementing there own logic to counter such errors there is no one rule to follow in such scenarios. It depends on the browser on what it does.

    You should never rely on the browser to correct your mistake. Always rely on yourself for better cross browser compatibility

提交回复
热议问题