mozilla / learning.mozilla.org

This repo is for tracking initiatives of the Mozilla Learning Networks team.
https://learning.mozilla.org
Mozilla Public License 2.0
60 stars 91 forks source link

Adjust width of headlines to avoid orphans #171

Closed davidascher closed 9 years ago

davidascher commented 9 years ago

Is it possible to, using CSS, avoid lonely word orphans after a line break? I find that happens fairly regularly, and when dealing with center-aligned titling, it irks.

e.g.

screenshot 2015-03-07 16 17 18

/cc @k88hudson @Pomax @gesa @toolness

What I'd love is a directive that tells CSS "adjust the width so that lines are roughly same length when rendered.

As a workaround for this site, we should convert the last space before Web. to have a leading &nsbsp;, or switch to a left-aligned layout.

davidascher commented 9 years ago

or set a max-width, although that will be localization-fragile.

k88hudson commented 9 years ago

Here's an (old) article detailing the problems with line balancing in css if you're interested, it's a good one. http://blogs.adobe.com/webplatform/2013/01/30/balancing-text-for-better-readability/.

My personal recommendation is to set max-width, as long as it's not too unreasonably small, and possibly behind a media-query. This is usually what I do. If you really wanted to get crazy detailed you could do different max-widths/break points namespaced under html[lang^="en"], html[lang^="fr"] etc.

The other option here is to use conditional <br> tags, behind media queries, but I this is even more difficult to do with localization.

davidascher commented 9 years ago

Thanks!

text-wrap: balance would be lovely. Where do I vote? ;-)

Also: it's a sign of the times that this problem doesn't have a cute name like orphan or widow -- it only shows up in computer-laid-out type, as no human typesetter would make that mistake.

k88hudson commented 9 years ago

@davidascher Some have suggested an orphans property, so orphans: 5 would require a minimum of 5 words on a next line :P

hannahkane commented 9 years ago

@davidascher, did we arrive at a solution for this one?

vazquez commented 9 years ago

I will submit a PR for this.

vazquez commented 9 years ago

orphans is not supported in FF :/ text-wrap: balance is not something that is natively supported by CSS. We need to import a library for this to work.

It looks like max-width with media queries is the way forward.