Home >Web Front-end >CSS Tutorial >How Can I Prevent Line Breaks After Hyphens in My HTML?
Overcoming Line Breaks After Hyphens
The challenge of preventing line breaks after hyphens is encountered when working with specific browser compatibility requirements. For instance, in Safari, hyphens can cause line wraps at the end of lines, as seen in examples like "3-n3/8".
To address this issue in a browser-agnostic manner, the non-breaking hyphen character (‑) can be employed. Unlike the zero width no-break character, this character effectively prevents line breaks after hyphens.
Implementation:
Simply replace the standard hyphen (-) with the non-breaking hyphen character in the HTML code. For example:
<p> 3-&#8209;3/8&rdquo; </p>
Benefits:
The non-breaking hyphen:
By utilizing the non-breaking hyphen, developers can ensure that hyphens remain intact and do not cause unsightly line breaks, regardless of the viewport size or browser used.
The above is the detailed content of How Can I Prevent Line Breaks After Hyphens in My HTML?. For more information, please follow other related articles on the PHP Chinese website!