【他山之石】Leading-Trim: The Future of Digital Typesetting:数字排版的未来 —— Leading-Trim

文章目录

  • 【他山之石】Leading-Trim: The Future of Digital Typesetting:数字排版的未来 —— Leading-Trim
    • How an emerging CSS standard can fix old problems and raise the bar for web apps
    • 1. The problem with text boxes today
    • 2. How we got here: a history lesson
    • 3. Workarounds are just workarounds
    • 4. Introducing leading-trim
    • 5. Leading-trim fixes alignment issues
    • 6. Other immediate impacts: consistency and workflow improvements
    • 7. Small change, big implications
    • 8. Microsoft’s role in this effort
      • 8.1 Special thanks
      • 8.2 Questions or comments?
      • 8.3 Reference

写在前面
本文是《CSS in Depth》全新第2版12.1节(详见我的 CSS 同名翻译专栏 【CSS in Depth 2 精译_073】)中提到的一篇延伸阅读材料。由于没找到免费的完整版转载,特此整理,择日再翻译成中文,敬请关注!

【他山之石】Leading-Trim: The Future of Digital Typesetting:数字排版的未来 —— Leading-Trim

How an emerging CSS standard can fix old problems and raise the bar for web apps

by Ethan Wang, Aug 18, 2020 (9 min read)

fig12.8.1

1. The problem with text boxes today

In a standard text box, there’s almost always extra space above and below the actual text. Because of this, when you use a text box to measure and implement spacing, it ends up larger than you intended. The bigger the line height, the bigger the problem. The example below shows distances between text boxes set to 32px. As you can see, all the vertical spacing is visually much bigger than 32px, even though you set them all to the same value.

fig12.8.2

This is a common problem that spans tools and platforms. In my last Medium article, I talked about how I use the 4px baseline grid to measure spacing around text and achieve better visual accuracy. Knowing the imperfections of this approach, I kept searching for a better solution. Last June, I came across an emerging CSS feature spec called leading-trim. I’ve been working with the author of the spec, an expert from the W3C CSS Working Group, fantasai, to make sure Microsoft Design can be a part of this transformative work.

Today, we’re excited to announce that Microsoft Design is sponsoring the authoring of this new spec. This article gives an introduction to this new CSS standard, leading-trim, and what it could mean for web designers and developers.


2. How we got here: a history lesson

To understand how this became a problem, specifically on the web, we need to go back in the history of typography. Around 140 years ago, type was still set manually with individual lead boxes. To make text more readable, typesetters would put strips of lead to space lines out. (That’s where the word “leading” came from 😉) The height of the type block plus the leading add up to the total line height.

fig12.8.3

Early graphic design software in the ’80s kept the same tradition where people could add bottom leading directly to control spacing between lines, and line height would increase as a result. Other software made it a two-way street, where people could adjust the line height directly. But behind the scenes, bottom leading was always the part that was changing.

Things diverged after the invention of the web, with CSS1 debuting in 1996. The people who created CSS1 decided to split leading in half and put it above and below each line. They called it “half-leading.” Their reason was simple: make text boxes looks even.

fig12.8.4

【Leading was split in half and put above and below each line since CSS1. The browser window shown above is Internet Explorer 3.0. IE3 was the first commercial browser with CSS support. The font used is Verdana, released with the Core Fonts for the web project initiated by Microsoft back in 1996. In case you are wondering, the curves in the browser chrome are not a watermark.】

While half-leading creatively avoided uneven bounding boxes, it introduced its own problems. Each font size in a font family comes with a default line height. Default line height is usually designed to be taller than the text it contains to accommodate certain characters and accent signs. Increasing line height then adds two half-leadings, making the text box even bigger. Half-leading, together with the extra space reserved in the default line height, is the root of our text box frustrations today.

fig12.8.5 The anatomy of your average text box

【The anatomy of your average text box】


3. Workarounds are just workarounds

Some of our most popular UI design tools, such as Figma and Sketch, seem to have adopted the half-leading model and render text this way. So we experience this problem in both our design tools and browsers.

The workaround on the design side is relatively easy: you can ignore the bounding box and directly measure space against text’s cap height and baseline. It’s a manual process because most design tools don’t have snap targets for cap height and baseline, but I know we designers will do anything to make our design look good!

But if we take this approach, developers still implement only the bounding box spacing in CSS. Therefore, they would get seemingly random spacing values.

To mitigate this randomness issue, developers can “crop” the text box in CSS with negative margins. But the negative margins would need to be determined manually and are font specific, and therefore “random.” Any font, browser, operating system or locale change will inevitably throw off your carefully set margins. Besides, this technique is generally not a good coding practice and can cause unintended side effects.


4. Introducing leading-trim

Leading-trim seeks to change the standard we’ve been using for 24 years.

Leading-trim is a new CSS property that the CSS Working Group is introducing. Just as the name suggests, it works like a text box scissor. You can trim off all the extra space from reference points of your choice with just two lines of CSS.

fig12.8.6

h1 { text-edge: cap alphabetic;leading-trim: both;
}

The example above first uses text-edge (also a new property) to tell the browser the desired edge of the text is the cap height and the alphabetic baseline. Then it uses leading-trim to trim it from both sides. Note that leading-trim only affects the text box; it doesn’t cut off the text within it.

These two simple lines of CSS create a clean text box that hugs your text. This helps you achieve much more accurate spacings and create a better visual hierarchy.

fig12.8.7


5. Leading-trim fixes alignment issues

With leading-trim, you can finally fix all the mysterious alignment issues you see on your site. For example, maybe your text doesn’t always look vertically centered in a container even though the text box is.

fig12.8.8

The extra space reserved in the default line height causes text to not always be centered in the text box. With leading-trim, you can reliably vertically center your text.

fig12.8.9

Each font is also designed differently. It comes with its own default line height and the text within it could have a different size and baseline position. So sometimes even if font size, line height, and text box position stay the same, changing the font changes the alignment of the text, just like the example below.

fig12.8.10

In the second example, you can see how leading-trim prevents this and keeps the text true to form.

fig12.8.11


6. Other immediate impacts: consistency and workflow improvements

Leading-trim goes beyond making spacings and alignment more accurate. It plays a key role in enabling an accurate spacing system, paving the way for design accuracy and consistency and efficient design-to-dev handoff.

A spacing system is like t-shirt sizes for spacing values. Like how a color palette or type ramp is set up in code today, spacing values can also be represented using CSS classes. (To learn more about spacing systems, check out Nathan Curtis’s Space in Design System.)

There are a lot of benefits to having a spacing system. Designers can make spacing decisions faster, and developers can set up corresponding spacing variables to eliminate random, hard-coded values in code. But today, even if we set up a spacing system, it wouldn’t be accurate for text elements because of the extra space in the text box. If we try to ignore the bounding box in our design and “crop” the text box in code, we run into those tricky workaround issues.

fig12.8.12

【A spacing system applied to text elements without leading-trim 😕】

With leading-trim, designers can finally unlock the power of a spacing system. Starting from design, we can apply a spacing system on top of measuring optical spacing (measure against type’s cap height and baseline). In addition to accurate spacings, it will help us establish better visual hierarchies and have more confidence in our layout.Overall, we can improve design consistency across the board.

The design-to-dev handoff process will also be much smoother because developers will be able to set up the exact same system and avoid spending tons of time on layout bugs. Most importantly, the spacing systems leading-trim enables will help us deliver more visually polished products that our users trust and enjoy.


7. Small change, big implications

Beyond craftsmanship and making handoff more efficient, we hope leading-trim will turn a new page for digital typesetting, eventually motivating improvements to other standards and platforms, starting with OpenType.

Leading-trim works by browsers accessing the font metrics to find, for example, the cap height and baseline. As the standard font format, OpenType specifies what metrics to include in the font file. OpenType has been jointly developed by Microsoft and Adobe as an extension of Apple’s TrueType font format since 1997. While today OpenType has robust support for Latin scripts and CJK languages, it still lacks key metrics for other less commonly used writing systems such as Hebrew or Thai. As people adopt leading-trim, we hope this leads the way for us to add more font metrics of other writing systems to OpenType.

Ultimately, we hope leading-trim helps improve OpenType and its internationalization by ensuring equal typographical capabilities across the world. That’s just the start of the ecosystem. Once leading-trim becomes available in all the modern browsers, desktop applications that are built using web technologies, such as Figma, Teams, and VS Code, will also be able to utilize it.

The impact can also go beyond the web. Sketch has already added snap targets for cap height and baseline. Instead of holding down the Option key to show bounding box to bounding box spacing, you can hold down Control + Option to see baseline to cap height spacing. It makes measuring optical spacing a lot easier. More importantly, this shows the slow shift in the way people approach digital typesetting. We are hoping leading-trim can further encourage this change. And through this mindset change, beyond just snap targets, leading-trim might just become a new text rendering standard in our design tools and extend to our operating systems.


8. Microsoft’s role in this effort

Leading-trim is a part of the CSS Inline Layout Module Level 3 specification that fantasai is working on. There are four other proposals included in the spec with a common goal of fixing CSS text layout.

Microsoft Design is sponsoring the authoring of this spec as the first step of CSS standardization. The spec will provide the blueprint for each browser to implement so web developers and designers around the world can use the features it introduces. But we hope our involvement goes beyond that, from extending the OpenType specification to browser implementation, product integration and testing, and more.

We believe that this new specification will help move the needle in accessibility, internationalization, and craftsmanship, and we are extremely proud to be part of this initiative.

We look forward to the partnership with the CSS Working Group and fantasai, the cross-team collaboration that will happen across Microsoft, and are excited about what the future holds.


8.1 Special thanks

I’d like to extend a special thanks🎉 to my content designer, Perry Holzknecht and my manager Annie Bai for their help and support along this journey. I would also like to thank Jonah Sterling (our General Manager for Cloud+AI Studio), his design leadership team, and Ana Arriola (General Manager & Partner for AI Product Design & UX Research, NeXT.lab) for their help and guidance throughout this process. Thank you so much🎉 for making this happen!

And last, but not least, a huge thank you🎉 to Brook Durant (Senior Design Manager at Web Experience Collective (WXC) Studio) and Albert Shum (CVP of Design for WXC Studio) for sponsoring this effort!

8.2 Questions or comments?

Please don’t hesitate to let me know if you have any questions or comments. Additionally, fantasai is also welcoming feedback on the CSS Inline Layout Module Level 3 spec in the CSSWG’s GitHub repository.

8.3 Reference

Marcin Wichary’s Figma blog post Getting to the bottom of line height in Figma gave me the knowledge and inspiration that led me on this journey. I highly recommend reading it!


To stay in the know with Microsoft Design, follow us on Twitter, Instagram, Facebook or join our Windows Insider program. And if you are interested in joining our team at Microsoft, head over to aka.ms/DesignCareers.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/889938.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[java] 简单的熔断器scala语言案例

failureRateInterval时间内如果addEx(错误)达到 maxFailuresPerInterval 次数,则fused方法返回true,表示触发熔断,进入冷却期coolingInterval,冷却期内fused方法返回true,冷却期过后进入下一个错误统计周期。 scala语言完成 imp…

【k8s集群应用】Kubernetes 容器编排系统

文章目录 Kubernetes 容器编排系统背景与发展Kubernetes 基本概念Kubernetes 集群架构与组件Kubernetes 核心组件Master 组件配置存储中心Node 组件 Kubernetes核心概念1. Pod2. Pod控制器3. Label与Label选择器4. Service5. Ingress6. Volume7. Name与Namespace K8S创建Pod资源…

梳理你的思路(从OOP到架构设计)_简介EIT造形

目录 1、 复习<基类 /子类>的扩充(extends)结构 典型的<基类/子类>代码结构 <基类/子类>代码结构的变形 2、 从<基类/子类>结构到EIT造形 3、 EIT造形的基本形与变形 1、 复习<基类 /子类>的扩充(extends)结构 典型的<基类/子类>代码…

CSS系列(11)-- 滤镜与混合模式详解

前端技术探索系列&#xff1a;CSS 滤镜与混合模式详解 &#x1f3a8; 致读者&#xff1a;探索视觉效果的艺术 &#x1f44b; 前端开发者们&#xff0c; 今天我们将深入探讨 CSS 滤镜与混合模式&#xff0c;学习如何创建独特的视觉效果。 滤镜效果详解 &#x1f680; 基础滤…

[创业之路-196]:华为成功经验的总结与教训简单总结

目录 前言&#xff1a; 成功经验 教训归纳 前言&#xff1a; 华为作为世界领先的通信设备制造商&#xff0c;其成功经验与教训值得深入探讨。 以下是对华为成功经验的总结与教训的归纳&#xff1a; 成功经验 战略定位明确&#xff1a; 华为始终坚持“死死抓住核心技术”…

Rust vs C: PNG解码器性能之争的启示

在系统编程领域,C语言一直是性能标杆。但最近一个现象引发了广泛讨论:用 Rust 实现的 PNG 解码器性能竟然超越了 C 语言版本。这个看似反直觉的结果背后,折射出现代编程语言发展的新趋势。 让我们深入解析这个有趣的技术现象。PNG解码本质上是把压缩的图像数据还原成像素数据的…

【收藏】Cesium 限制相机倾斜角(pitch)滑动范围

1.效果 2.思路 在项目开发的时候&#xff0c;有一个需求是限制相机倾斜角&#xff0c;也就是鼠标中键调整视图俯角时&#xff0c;不能过大&#xff0c;一般 pitch 角度范围在 0 至 -90之间&#xff0c;-90刚好为正俯视。 在网上查阅了很多资料&#xff0c;发现并没有一个合适的…

利用编程获得money?

在当今数字化时代&#xff0c;编程技能为人们开辟了众多赚钱途径。无论你是编程新手还是经验丰富的开发者&#xff0c;都能在广阔的市场中找到适合自己的盈利方式。以下是一份详细的用编程赚钱指南。 一、自由职业平台 像 Upwork、Freelancer 和 Fiverr 等知名自由职业平台&am…

复习打卡Linux篇

目录 1. Linux常用操作命令 2. vim编辑器 3. 用户权限 4. Linux系统信息查看 1. Linux常用操作命令 基础操作&#xff1a; 命令说明history查看历史执行命令ls查看指定目录下内容ls -a查看所有文件 包括隐藏文件ls -l ll查看文件详细信息&#xff0c;包括权限类型时间大小…

MyBatis-Plus 实用工具:SqlHelper

SqlHelper 是MyBatis-Plus的一款SQL 辅助工具类&#xff0c;提供了一些常用的方法&#xff0c;简便我们的操作&#xff0c;提高开发效率。文档 最常用的是SqlHelper.table(Obj.class) 返回的 TableInfo 对象通常包含以下常用方法&#xff1a; 1. getTableName() 获取表名。示例…

游戏无界,RayLink远程控制电脑打造极致游戏体验

在数字化浪潮席卷全球的今天&#xff0c;电子游戏已经成为我们日常生活中不可或缺的娱乐方式。“游戏无界限”的理念正在逐步改变着玩家们的游戏体验。远程操控电脑技术的兴起&#xff0c;仿佛为游戏世界打开了一扇新的大门&#xff0c;打破了时间和空间的限制&#xff0c;让玩…

【LeetCode】2406、将区间分为最少组数

【LeetCode】2406、将区间分为最少组数 文章目录 一、数据结构-堆、贪心1.1 数据结构-堆、贪心1.2 多语言解法 二、扫描线2.1 扫描线 一、数据结构-堆、贪心 1.1 数据结构-堆、贪心 题目已知一些区间, 需要尽量合并, 使 组 最少. 可以用图解画一下 因为尽量合并, 为了紧凑, …

sqlserver2019发布订阅的MSSQL_REPL55012错误处理

利用SQL2019进行发布时报如下错误 Message: An unspecified error had occurred in the native SQL Server connection component. Stack: 在 Microsoft.SqlServer.Replication.Snapshot.SqlServer.NativeBcpOutProvider.ThrowNativeBcpOutException(CConnection* pNativeCo…

彻底理解如何优化接口性能

作为后端研发&#xff0c;必须要掌握怎么优化接口的性能或者说是响应时间&#xff0c;这样才能提高系统的系能&#xff0c;本文通过如下两个方面进行分析&#xff1a; 一.后端代码 有如下几步&#xff1a; 1.缓存机制 这是最场景的方式&#xff0c;当使用了缓存后&#xff0c;…

Java性能调优 - JVM性能监测及调优

JVM 内存模型概述 堆 堆是JVM内存中最大的一块内存空间&#xff0c;该内存被所有线程共享&#xff0c;几乎所有对象和数组都被分配到了堆内存中。堆被划分为新生代和老年代&#xff0c;新生代又被进一步划分为Eden和Survivor区&#xff0c;最后Survivor由From Survivor和To Su…

【计算机网络】期末考试预习复习|上

作业讲解 物理层作业 共有4个用户进行CDMA通信。这4个用户的码片序列为&#xff1a; A: (–1 –1 –1 1 1 –1 1 1)&#xff1b;B: (–1 –1 1 –1 1 1 1 –1) C: (–1 1 –1 1 1 1 –1 –1)&#xff1b;D: (–1 1 –1 –1 –1 –1 1 –1) 现收到码片序列&#xff1a;(–1 1 –…

Element plus 下拉框组件选中一个选项后显示的是 value 而不是 label

最近刚进行 Vue3 Element plus 项目实践&#xff0c;在进行表单二次封装的时候&#xff0c;表单元素 select 下拉框组件选中一个选项后显示的是 value 而不是 label&#xff0c;下面上代码&#xff1a; 原来的写法&#xff1a; <el-selectv-if"v.type select"…

SpringBoot2+Vue2开发工作管理系统

项目介绍 在工作中使用的管理系统&#xff0c;可以随手记录一些笔记、可以汇总一些常用网站的链接、可以管理自己负责的项目、可以记录每日日报和查看历史日报、可以记录加班情况、可以记录报销内容、可以编写文章文档。 系统功能 我的笔记快捷入口项目管理今日日报我的日报…

前端的Python入门指南(完):错误和异常处理策略及最佳实践

《前端的 Python 入门指南》系列文章&#xff1a; &#xff08;一&#xff09;&#xff1a;常用语法和关键字对比&#xff08;二&#xff09;&#xff1a;函数的定义、参数、作用域对比&#xff08;三&#xff09;&#xff1a;数据类型对比 - 彻底的一切皆对象实现和包装对象异…

C语言实现八大排序算法

目录 1.插入排序 1.1 直接插入排序 1.2 希尔排序 2. 选择排序 2.1 直接选择排序 2.2 堆排序 *TopK问题&#xff1a; 3. 交换排序 3.1 冒泡排序 3.2 快速排序 1. Hoare版本 2. 挖坑法 3. 前后指针法 4. 快速排序优化 5. 非递归快速排序 4.归并排序 1.递归式归并…