CSS中em和en有什么区别

发布于 2024-12-31 22:11:29 字数 91 浏览 4 评论 0原文

我正在使用一些(有问题且奇怪的)CSS,我想知道在确定大小时 en 和 em 之间的区别是什么 font-size:12en;高度:3em;

I am working with some (problematic and strange) css, and I am wondering what the difference between en and em is when determining sizes font-size:12en; height:3em;.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甩你一脸翔 2025-01-07 22:11:29

它在 HTML/CSS 中无效,但在非网络印刷机中使用:
维基百科在 em 下提到了它:

em 空格 ( ) 的宽度定义为 1 em,em 破折号 (—) 也是如此。
相比之下,较窄的单位 en 是半个 em。

It is invalid in HTML/CSS however it is used in non-web print presses:
Wikipedia mentions it under em:

The width of the em space ( ) is defined to be 1 em, as is the em dash (—).
By contrast, the narrower unit en is half an em.

要走干脆点 2025-01-07 22:11:29

在 CSS 中,“em”是一个相对印刷单位,等于字体大小。如果您的字体大小是 12px,那么该元素的 1em 就是 12px。由于“em”是相对测量单位,因此当对具有不同字体大小的多个元素进行排版更改时,这会有所帮助,例如,如果您有:

<style> 
h1{ font-size: 24px; }
p{ font-size: 15px; }
.spacedout{ letter-spacing:1em; }
</style>

<h1 class="spacedout">Heading</h1>
<p class="spacedout">Paragraph</p>

那么字母之间的间距在视觉上将是相等的。

In CSS 'em' is a relative typographical unit that is equal to the font-size. If your font-size is 12px, then 1em is 12px for that element. Since 'em' is a relative unit of measurement, this helps when making typographical changes to multiple elements with different font sizes, for instance if you have:

<style> 
h1{ font-size: 24px; }
p{ font-size: 15px; }
.spacedout{ letter-spacing:1em; }
</style>

<h1 class="spacedout">Heading</h1>
<p class="spacedout">Paragraph</p>

then the spacing between letters would be visually equal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文