简体   繁体   中英

How to enable line break at hyphens on Firefox

Chrome, IE, and Safari break lines at hyphens but Firefox doesn't.

Is there any way to make Firefox break lines at hyphens, like other browsers?

Insert the <wbr> tag after the hyphen. This tag is not present in any HTML specification (yet—it is in HTML5 drafts), but it has worked for a long time in browsers.

Firefox automatically treats a hyphen as allowing a line break after it when there are sufficiently many characters around the hyphen. But if you wish to allow line breaks more widely than that, use <wbr> , eg pre-<wbr>war .

Not easily. Try inserting a zero-width space ( &#8203; ) after each hyphen. For example:

a-&#8203;really-&#8203;long-&#8203;hyphenated-&#8203;phrase

This will make Firefox wrap as if there's a space, but it won't visually display that space.

It's easier to implement this if you have something processing your output server-side. Just run hyphens through a quick string replace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM