`
liudaoru
  • 浏览: 1579318 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

The CSS ex unit[z]

阅读更多

From: www.xs4all.nl/~sbpoley/webmatters/emex.html

Summary

I have a few times seen it suggested that the ex unit is useful for setting the widths of CSS boxes. However, having done a little experimenting with the em and ex units in CSS, I do not share that view.

In fact my conclusion is that the CSS ‘ex’ unit is practically useless. A unit based on a typical character width would indeed have been useful in getting CSS boxes to wrap at approximately the same point in the text, regardless of which font the reader is using. But the ex is defined as follows:

The ‘ex’ unit is defined by the font’s ‘x-height’. The x-height is so called because it is often equal to the height of the lowercase "x". However, an ‘ex’ is defined even for fonts that don’t contain an "x".

However, if one is defining the height of a box in terms of the font-size, one clearly wants to use the font-size itself – i.e. the em. While if one is defining the width of a box, it is not obvious why there is any advantage in using the x height. I have racked my brains on this one, and invited opinions on Usenet; I cannot think of any use for the ex unit. If you can, please contact me.

Was this something that went wrong during the creation of the CSS specification?

The rest of this article gives some background for this.

Examples – box sizes

Below are some boxes with the widths shown. Of the browsers I have tried, only Mozilla – and so presumably also other Gecko-based browsers, such as Netscape 6/7 – uses the ex units according to specification. Opera and Internet Explorer seem to assume 1 ex is 0.5 em and leave it at that. Actually half an em does correspond to a typographical unit, but another one: the en.

(Since the original version of this page it has been pointed out to me that the Opera / Internet Explorer behaviour is dictated by the limitations of the Windows operating system. Apparently the Gecko browsers do all their own character rendering, which goes some way to explain why they are so large.)

 

30 em Times New Roman

A sentence made up of lots of very short words to see how the wrap goes with some em and ex values.

 

30 em Arial

A sentence made up of lots of very short words to see how the wrap goes with some em and ex values.

 

60 ex Times New Roman

A sentence made up of lots of very short words to see how the wrap goes with some em and ex values.

 

60 ex Arial

A sentence made up of lots of very short words to see how the wrap goes with some em and ex values.

 

60 ex Verdana

A sentence made up of lots of very short words to see how the wrap goes with some em and ex values.

 

60 ex Bernhard Fashion BT

A sentence made up of lots of very short words to see how the wrap goes with some em and ex values.

 

For those people using other configurations: the image below shows how the above boxes look in Mozilla on Windows. You can see how the Bernhard Fashion font gets a very narrow box because it has very low lower-case letters, though it is actually not much narrower than Times New Roman. It is hard to see how this is useful.

[Appearance of text blocks in Mozilla]

Now, it is possible to create examples where the ex unit does give a more consistent block size (at any rate in Mozilla). This is the case where the fonts concerned have a similar aspect ratio for their lower-case letters (ratio of height to width) but very different aspect values (ratio of em to ex). This is however not generally true.

Font sizes

A helpful e-mail from a typesetter pointed out that it can be useful in typesetting to set fonts according to their ex size: fonts with the same ex size tend to be about equally legible. I suspect this may have been why the ex unit was originally introduced: the intention was to be able to specify something like { font-x-size: 1ex } This could have been very useful: if the author’s selected font had a significantly different aspect value from the reader’s selected default, it would set a font size of approximately equal readability. However font-x-size never materialised.

Stan Brown did point out a conceivable use for the ex. If one wanted to use a graphic to represent a character which has no defined character entity reference, and the character was required to be the size of a lower-case letter, then in principle one could set the height of the image to 1ex. In practice however browser resizing of images is not good enough to make that effective, and in any case one would have to search hard to find a character for which this was necessary.

It has also been suggested that the ex might be useful for margin/padding settings. I guess this is just about possible, at least for top and bottom, though again whether it gives better results than the em probably depends heavily on which fonts are in use.

Winding up

In summary then, although the ex may just be marginally useful in one or two circumstances, your web pages will not suffer if you ignore its existence completely.

Incidentally I’ve found an error in the CSS specification:

“In bicameral scripts, the subjective apparent size and legibility of a font are less dependent on their ‘font-size’ value than on the value of their ‘x-height’, or, more usefully, on the ratio of these two values, called the aspect value (font size divided by x-height). The higher the aspect value, the more likely it is that a font at smaller sizes will be legible.”

Given the last quoted sentence (and also the sentences that follow it in the specification) it is clear that the aspect value is not as stated, but is actually x-height divided by font-size.

Finally, I’ll mention an interesting article Typographical measurement systems on ems, ens and related matters. <!---->

分享到:
评论

相关推荐

    The New Css Layout

    The New Css Layout CSS 布局

    CSS:The Definitive Guide, 4th Edition[CSS权威指南](英文版)

    CSS(The Cascading Style Sheets, 层叠样式表)是构建网页和用户界面的一种样式表语言,它定义了如何在浏览器中显示HTML文档,从而实现内容与表现的分离。《CSS权威指南》第四版是CSS领域的重要著作,作者Eric A. ...

    The Zen of.CSS.Design(css禅意花园)

    The Zen of.CSS.Design(css禅意花园)The Zen of.CSS.Design(css禅意花园)The Zen of.CSS.Design(css禅意花园)The Zen of.CSS.Design(css禅意花园)

    The CSS Anthology: 101 Essential Tips, Tricks & Hacks, 3rd Edition

    The CSS Anthology: 101 Essential Tips, Tricks & Hacks is a compilation of best practice solutions to the most challenging CSS problems. The third edition of this best-selling book, published in full ...

    The.Zen.of.CSS.Design.-.Visual.Enlightenment.for.the.Web.part1

    The.Zen.of.CSS.Design.-.Visual.Enlightenment.for.the.Web.part1

    The Zen of CSS Design (3-3)

    The Zen of CSS Design ,绝佳的CSS设计图书

    Z01866Web前端开发技术 HTML、CSS、JavaScript 第2版.pdf

    Z01866Web前端开发技术 HTML、CSS、JavaScript 第2版

    Ultimate CSS reference

    the css reference. The reference for the css development

    CSS-Unit-Converter:在CSS单位之间转换值的简单工具

    CSS单位转换器 使用CSS单位转换器在几乎每个CSS 单位之间转换值。 请通过进行实际检查。 建造 确保已安装 安装所有依赖项 npm install 建立一切 npm run build 观看所有内容(并根据更改进行重建) npm run ...

    CSS The Definitive Guide, 4th Editio

    《CSS The Definitive Guide, 4th Edition》是一本权威的CSS(Cascading Style Sheets)指南,专为深入理解和应用CSS技术的开发者而设计。这本书由业界专家Eric A. Meyer撰写,是CSS学习者的必备参考书。第四版更是...

    CSS The Definitive Guide, 4th Edition(中文机翻)

    《CSS The Definitive Guide, 4th Edition》是一本权威的CSS(Cascading Style Sheets)指南,中文机器翻译版提供了对原英文版的辅助理解。这本书详细讲解了CSS的各个方面,对于深入理解和掌握CSS技术具有极大的价值...

    css课程.7z

    《CSS课程深度解析》 CSS,全称Cascading Style Sheets,即层叠样式表,是网页设计中不可或缺的一部分。本课程围绕“css课程”展开,通过一系列基础案例,旨在帮助学习者深入理解和掌握CSS的核心概念和技术应用。 ...

    CSS权威指南第四版.7z

    《CSS权威指南第四版》是前端开发者不可或缺的参考资料,它深入浅出地讲解了CSS(层叠样式表)这一核心技术。这本书英文版以其详尽的内容和丰富的实例,为读者提供了全面学习CSS的机会。通过阅读和实践书中代码,...

    react-css-themr, CSS模块易于主题化和组合.zip

    react-css-themr, CSS模块易于主题化和组合 响应 CSS ThemrCSS模块易于主题化和组合。$ npm install --save react-css-themr注意:对文档的反馈和贡献非常感谢。 为什么?在使用模块样式时,通常从同一

    css framework 漂亮的CSS

    Add the following four links to the &lt;head&gt; of your page:: &lt;link rel="stylesheet" href="../css/screen.css" type="text/css" media="screen, projection"&gt; &lt;link rel="stylesheet" href="../css/print.css" ...

    CSS CSS CSS

    CSS CSS 资料套装 CSS CSS 资料套装 CSS CSS 资料套装 CSS CSS 资料套装 CSS CSS 资料套装 CSS CSS 资料套装 CSS CSS 资料套装

    css.rar_css_the code

    This is the css code.

    CSS3秘籍 the missing manual 随书代码

    《CSS3秘籍 the missing manual》是一本深入探讨CSS3技术的专业书籍,随书附带的代码示例是学习和理解CSS3的关键辅助资源。这本书旨在帮助读者掌握CSS3的各种新特性和用法,从而创建出更加丰富、动态且响应式的网页...

Global site tag (gtag.js) - Google Analytics