像素与HTML / CSS中的点 [英] Pixels vs. Points in HTML/CSS

查看:118
本文介绍了像素与HTML / CSS中的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建HTML页面时,是否应该指定 margin 的像素或CSS中的点?



他们中的一个被认为是比另一个更好的实践吗?任何一个优点或缺点?

解决方案

使用 px em






Points(pt):用于打印介质(打印在纸上的任何东西等)。一个点等于1/72英寸。点与像素很像,因为它们是固定大小的单位,不能在大小上缩放。



一般来说, 1em = 12pt = 16px = 100% / strong>



[结论]







  • JohnB注意:这是 TEXT。 / strong>很明显你问过边距等事情。 (我假设你的意思是 padding )。因此,我会建议 px em






    $ b b



    点值仅适用于打印CSS!



    点是打印的?不。



    点数不是仅供打印。理论上,点用于定义绝对度量。像素不是绝对的,因为根据您的屏幕和选择的定义(不是分辨率),分辨率(每英寸像素)可以从很多(150dpi)或非常小(75dpi)。这意味着您的像素可以是一个大小,或者可能是一半的大小。这意味着你设计的文本在你的屏幕上是完全清晰可能看起来太大在你的客户端的屏幕上(请让文本更小,确定?)或太小,不可读的邻居的屏幕上(嘿,网站你告诉我关于另一天,你说你曾经工作过...我很难读文本很好,它是这么小)。



    点数解决这个问题。但是浏览器和操作系统需要管理它们。基本上,这意味着:



    浏览器必须使用给定值(例如10pt)和屏幕的真实分辨率来计算显示大小(以像素为单位)
    操作系统必须传递实际的当前分辨率,而不是默认值。


    b
    $ b


    When creating an HTML page, should I specify things like margins with pixels or with points in CSS?

    Is one of them considered to be better practice than the other? Any advantages or disadvantages to either one?

    解决方案

    Use px or em

    Points (pt): Points are traditionally used in print media (anything that is to be printed on paper, etc.). One point is equal to 1/72 of an inch. Points are much like pixels, in that they are fixed-size units and cannot scale in size.

    Generally, 1em = 12pt = 16px = 100%.

    [Conclusion]

    The winner: percent (%).

    • JohnB note: this is for TEXT. Obviously you asked about "things like margins." (I assume you mean padding also.) For that, I would recommend px or em. Personally, I switch, depending on the particular situation.

    MORE ARTICLES

    Point values are only for print CSS!

    (Comment further down)

    Points are for print? Nope.

    Points are not for print exclusively. Theoretically, points are for defining an absolute measure. Pixels are not absolute, since depending on your screen and chosen definition (not resolution), the resolution (pixels per inch) can go from a lot (150dpi) or very little (75dpi). Which means your pixels can be a size, or maybe half that size. Which means that text you design to be perfectly legible on your screen may look too big on your client’s screen ("please make the text smaller, ok?") or too small to be readable on your neighbor’s screen ("hey, the website you told me about the other day? the one you said you had worked on… well i couldn’t read the text very well, it’s so small").

    Points are a solution to this issue. But browsers and operating systems need to manage those. Basically, it means:

    browsers have to calculate the display size in pixels using the given value (say, 10pt) and the screen’s real resolution; operating systems have to communicate the real current resolution, and not a default value.

    Also:

    这篇关于像素与HTML / CSS中的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆