"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How Can I Prevent Line Breaks After Hyphens in My Text?

How Can I Prevent Line Breaks After Hyphens in My Text?

Published on 2024-12-22
Browse:399

How Can I Prevent Line Breaks After Hyphens in My Text?

Preventing Line Breaks After Hyphens

When working with text that contains hyphens, you may encounter issues where a line break occurs after the hyphen, creating an undesirable visual effect. This issue is particularly evident when dealing with hyphenated measurements or other elements that should be kept together as one word.

In browsers like Safari, this problem can arise due to the absence of recognition for the zero width no break character () when preventing line breaks. To address this situation, an alternative solution that universally works across browsers is the non-breaking hyphen (‑).

By utilizing the non-breaking hyphen, you can prevent line breaks from occurring after specific hyphens. Simply replace the regular hyphen with ‑ in the problematic instances, ensuring that the hyphenated text remains intact and unbroken even in narrow display areas.

To demonstrate this approach, consider the following example:

Original Text: 3-3/8"

Modified Text with Non-Breaking Hyphen: 3‑3/8"

By incorporating the non-breaking hyphen, you can prevent the line break from occurring after the hyphen, regardless of the display size or viewport width. This solution provides a reliable and effective method for maintaining the integrity of hyphenated text across different browsers and devices.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3