Are there any practical reasons to use “em” instead of “pt” font size units?

后端 未结 7 1481
南笙
南笙 2020-12-08 11:19

One CSS rule I have learned is that you should use the relative \"em\" font-size unit instead of the absolute \"pt\". The general idea is to set the font-size in your body t

相关标签:
7条回答
  • 2020-12-08 11:57

    px : changes with your screen resolution and other dependent issues

    em : irrespective of your screen resolution, it will be same for all

    0 讨论(0)
  • 2020-12-08 12:00

    See also http://www.killersites.com/mvnforum/mvnforum/viewthread?thread=4084

    0 讨论(0)
  • 2020-12-08 12:05

    Even if you hard-code the font-size in pixel, you can still use em for unit to specify margin, length, etc.. , similar to using em quad to indent a paragraph in the printing press anyway.

    Edit (After the poster changed from px to pt): If you want to be "pixel perfect", it's safer to go with px rather than pt, since different operating system has different dpi setting, and user change change dpi dramatically especially on Linux. PostScript point is defined to be 1/72 of an inch. An "inch" on screen can be anywhere between 72 pixels to whatever floats your boat.

    0 讨论(0)
  • 2020-12-08 12:06

    Some professional CSS developers that I know use "px" to define font sizes in their main stylesheet for modern browsers, then have a separate stylesheet for IE6 that specifies them using relative units. That way they achieve usability and allow font magnification on all browsers, but without having to compromise their design on modern browsers.

    (They actually go farther than that: their IE6 stylesheet turns off most block formatting and just lays everything out using a generic, mobile-ish look. That way IE6 users can see a simple layout, and everyone else gets the professional look where blocks actually float correctly.)

    0 讨论(0)
  • 2020-12-08 12:10

    1) IE6 is still widely used and is unable to resize the fonts defined in px. => Usability issues. That alone is a no-no.

    2) See CSS Units for example.

    3) Most authors agree to say that pt is mostly a print unit: at worst, use them in print stylesheets, where the resize problem disappears...

    0 讨论(0)
  • 2020-12-08 12:15

    Depending on the country where you live, you might actually end up breaking the law using pt instead of em, depending on how hard your legislature want to enforce rules. Here in the UK, there is a disability discrimination act, which has been used to target companies where their websites have been rendered in a fixed font. This is treated as discrimination because it disadvantages the partially sited who may have increased their browser font sizes to compensate - but your site still renders fonts at the size you set, and not at the size they would expect.

    Yes, it's harder to get to grips with relative font-sizes and fluid layouts, but if you want to comply with legislation, you have to take the time to get to grips with this.

    For local government work in the UK, targets have been set to ensure that websites follow Double A guidelines, one of which states "Use relative rather than absolute units in markup language attribute values and style sheet property values". See here.

    0 讨论(0)
提交回复
热议问题