CSS Inline Vertical Alignment
CSS Inline Vertical Alignment
Elika J. Etemad aka fantasai
W3C CSS Working Group Invited Expert
About Me
- 1999–2013 — Mozilla Project technical contributor
- 2004–present — CSS Working Group Invited Expert
- Specializations: layout, text, internationalization
Specs I've Worked On Since 2004
- CSS2.1
- CSS Style Attributes
- Selectors Levels 3 & 4
- CSS Pseudo-Elements Level 4
- CSS Scoping Level 3
- CSS Cascading & Inheritance Levels 3 & 4
- CSS Backgrounds & Borders Level 3
- CSS Images Level 3
- CSS Values & Units Level 3
- CSS Text Decoration Level 3
- CSS Text Level 3
- CSS Ruby Layout Level 1
- CSS Inline Layout Level 3
- CSS Line Grid Level 1
- CSS Rhythm Level 1
- CSS Logical Properties Level 1
- CSS Writing Modes Level 3
- CSS Box Alignment Level 3
- CSS Flexible Box Layout Level 1
- CSS Grid Layout Level 1 & 2
- CSS Box Sizing Level 3
- CSS Display Level 3
- CSS Fragmentation Level 3
- CSS Paged Media Level 3
- CSS Overflow Level 3
- CSS Fill & Stroke Level 3
- CSS Color Adjustment Level 1
Inline Layout Problems
- Variance across browsers
- → Tighten up definitions for line layout
- Jitter / inconsistent baseline-to-baseline spacing
- → Develop new model for line spacing
- No control over spacing above/below visible text
- → Trim using font metrics
- Drop caps don't align with text
- → Define specialized layout feature
Specification: CSS Inline Layout Level 3
Principles of Web Architecture
- Cross-Device & Cross-Platform
- World-Wide
- Forwards- and Backwards-Compatible
- No Datalossy Defaults
- Separated Content & Style
Constraints of CSS
- Unknown display size and orientation
- Unknown font availability
- Unknown content (user-generated, database-generated)
- Unknown language / writing system (localization, translation)
- No post-processing
Design Principles of CSS
- Flexible
- Powerful
- Robust
- Understandable
- Performant
Strict rhythms are important for multicol
Intra-Paragraph + Inter-Paragraph + Interrupts
Inter-Paragraph Spacing: lh
/rlh
units
Interrupts: Block Step Sizing
https://www.w3.org/TR/css-rhythm/
block-step-size: <length>
Requires used height = n × <length>, for an integer n
block-step-insert: margin | padding
block-step-align: auto | center | start | end
Typographer’s Line Placement Model
Goal: Look pretty.
Tools: Absolute measurements, post-layout adjustments.
Space lines for pleasant reading
and to accommodate ascenders/descenders/superscripts/subscripts/ruby.
Consistent baseline-to-baseline spacing creates vertical rhythm.
If your stuff overlaps it’s your fault.
So review and tweak your things before you print them!
CSS Line Box Model
Goal: Don't overlap content.
Tools: Boxes.
1. Put a bunch of stuff on a line.
3. Stack up the line boxes.
3. Stack up the line boxes.
Sizes found from font metrics
Identical font-size
, varying font-family
Identical font-size
, varying font-family
line-height: # | len | % | normal
Half-leading
line-height: 1.5
Base Case: Paragraph of Text, No Font Changes
Base Case: Paragraph of Text, No Font Changes
Base Case: Paragraph of Text, No Font Changes
Complication #1: Varying Font Families
Happiness is Rare
Fixing the Line Layout Model
Goal: Make typographers happy. Also, don't overlap the content.
How to Have Perfect Rhythm
- Start with the root inline box.
- Ignore all its contents.
- Perfect rhythm!
- But what about overlap?
How to Have Perfect Rhythm
- Start with the root inline box.
- Ignore all its contents.
- Perfect rhythm!
- But what about overlap?
Redefining “fit within a line box”
Items Without Half-leading
Open Questions
- Slack to handle font variations in tight settings?
- Allow overlap into next/previous line’s half-leading?
line-sizing: legacy | normal
legacy
- Do what CSS2.1 says
normal
- TBD! (Help us D?)
leading-trim-over: normal | text | cap | ex | ideographic
leading-trim-under: normal | text | alphabetic | ideographic
h2 { leading-trim: cap; }
h2 { leading-trim: cap; }
h2 { leading-trim: cap; }
h2 { leading-trim: cap; }
- Fully control spacing between text and borders
- Position text based on font metrics
- Better optical centering
I thought this was a World-Wide Web?
Open Questions
- Internationalization?
- Behavior at page/column breaks?
- Separate cascading/inheritance of metric vs. trigger?
- Multiple font sizes on the first/last line?
match baselines, then shift
match baselines, then shift
But which baseline?
In a well-designed mixed-script font, the glyphs are positioned in the coordinate space to harmonize with one another when typeset together. The baseline table is then constructed to match the shape of the glyphs, each baseline positioned to match the glyphs from its preferred scripts.
dominant-baseline: auto | alphabetic | ideographic | central | mathematical | …
vertical-align: <'alignment-baseline'> || <'baseline-shift>
└ alignment-baseline: baseline | alphabetic | ideographic | central | …
└ baseline-shift: sub | super | <length>
initial-letters: 2;
initial-letters: 2;
initial-letters: 2;
Your metrics are bad, and you should feel bad.
initial-letters: 2;
initial-letters: 2;
Variance
Tighten up definitions for line layout...
... not glamorous, but necessary.
CSS Inline Layout Level 3: Scope
- vertical alignment
- line height calculations
- inline box model
- drop caps
CSS Inline Layout Level 3: Goals
- Fix ambiguities
- New line height model
- Control spacing above/below text
- Native drop caps
CSS Inline Layout Level 3: Impact
- Fixing vertical rhythm is a top request from typesetters.
- Drop-caps are highly desired; workarounds are complicated, painful, fragile, and often have poor accessibility.
- Trimming to font metrics necessary to control spacing without font-specific magic numbers.
- Better internationalization.
The impact on the Web community will be higher-fidelity typesetting and layout of text, with good accessibility and fallback behavior, simply through a few lines of intentional CSS rather than struggling with magic numbers and negative margins and, in some cases, JavaScript and/or extra markup.
Standardization: Output
- Specifications
- Implementations
- Tests
Spec Development Process
- Working Draft
- Candidate Recommendation
- Recommendation
Standards & Interoperability
- Specifications
- Layout Engines
- Test Suites
- Web Content
-
How to Help
- Sponsor specification development
- Encourage browser engineering teams
- Lobby OpenType technologists (specs, tools, foundries)
- Contribute QA