为什么使用ems填充&am​​p;浏览器边距现在正确缩放? [英] Why use ems for padding & margins with browsers now scaling correctly?

查看:179
本文介绍了为什么使用ems填充&am​​p;浏览器边距现在正确缩放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想知道这个问题有一段时间,并创建了一个像素版本和em版本,以比较差异放大时 - 没有。我读过的大部分内容都是你需要让它们具有可扩展性,但我认为现在所有现代浏览器都可以正确缩放。只要你将CSS中的基本字体大小设置为ems / rems,以像素为单位的填充和边距将按比例缩放,如果他们是ems。我没有什么东西吗?

I've been wondering about this questions for some time and created a pixel version and and em version to compare the differences when zoomed in - there were none. Most of what I've read states something like "you need to make them ems for scalability" but I think it's a moot point now with all modern browsers scaling correctly. As long as you set the base font-size in your CSS to ems/rems, padding and margins written in pixels will scale accordingly as they would if they were ems. Am I missing something?

推荐答案

EM(et al)单位不用于视口缩放 - 它们相对于当前字体大小。他们的设计工作,如果我使我的字体非常大(因为我的眼睛很差)或非常小(因为我是年轻的,有鹰的眼睛),我想要文本周围的白色空间缩放与文本。一般来说,人们不想要20 pt文本与段落之间的5像素边距,也不是10 pt文本与50像素边距。

EM (et al) units are not for view-port zooming - they are relative to the current font size. They are designed to work such that if I make my font very large (because my eyes are poor) or very small (because I am young and have the eyes of an eagle) I want the white-space around the text to scale with the text. Generally, one doesn't want 20 pt text with a 5 pixel margin between paragraphs, nor 10 pt text with a 50 pixel margin.

例如,一个人想要段落之间大约有 N 行空格的文本。

For example one wants text with approximately N lines of white-space between paragraphs. Using N em vertical margins achieves a spacing which adapts to the font size actually rendered.

在现代网络中,em(et al)单位使用 em em垂直边距实现了适应实际渲染的字体大小的间距。仍然有自己的位置;但他们不是一切。基本上,你必须问自己,这个大小应该随字体变化吗?

In the modern web, em (et al) units still have their place; but they are not for everything. Essentially, you have to ask yourself, "should this size change with the font?"

此外,如果你决定更改你的身体文本字体大小怎么办?许多其他布局值从正文大小流出。假设您确定默认的浏览器大小为16pt-18pt比您现在使用的10pt大小更有意义。如果你用ems设置适当的东西,那么当你增加基数时,其他的一切都会随之增加。

Also, what if you decide to change your body-text font size? Many other layout values flow from that body-text size. Say you decide that the default browser viewing size of 16pt-18pt makes more sense than the 10pt size you are now using. If you have set the appropriate things with ems then when you increase the base everything else increases proportionately with it.

这篇关于为什么使用ems填充&am​​p;浏览器边距现在正确缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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