Can I use CSS to justify text with hyphenating wor

2020-07-09 08:22发布

I have a div that is too narrow to text-align:justify (gaps too wide), but yet looks un-uniform when right- or left-justified, because then there is a large gap at the end of lines. Left-justified looks best, but could I use hyphenation, like in books? Using CSS?

3条回答
该账号已被封号
2楼-- · 2020-07-09 08:50

You can use hyphens: auto provided that you have declared the content language in HTML, e.g. using <html lang=en-US>.

Browser support is still limited but getting better, see http://caniuse.com/css-hyphens

For good quality, you may need to manually control hyphenation e.g. by using soft hyphens (&shy;) in words that might otherwise be hyphenated wrong.

查看更多
家丑人穷心不美
3楼-- · 2020-07-09 08:51

Hyphenation is language-dependent; you can't just put overflowing characters on the next line and get the same effect that you do in books. Hyphenation rules are actually pretty complicated (see http://dictionary2.classic.reference.com/writing/styleguide/division.html), and the only way that you can do it properly (like in books) is either manually or via a client-side or server-side script; I'm pretty sure it can't be done using only css.

You might want to use something like http://code.google.com/p/hyphenator/

查看更多
劳资没心,怎么记你
4楼-- · 2020-07-09 08:57

For hyphenation in html, there are javascript programs to add what's needed to the text. such as http://code.google.com/p/hyphenator/

Support for brower buildin hyphenation is unreliable and improvement in its support is doubtful.

查看更多
登录 后发表回答