Home > Web Front-end > CSS Tutorial > How Can I Prevent Unwanted Line Breaks After Hyphens in HTML?

How Can I Prevent Unwanted Line Breaks After Hyphens in HTML?

Mary-Kate Olsen
Release: 2024-12-04 12:54:11
Original
764 people have browsed it

How Can I Prevent Unwanted Line Breaks After Hyphens in HTML?

Eliminating Line Breaks After Hyphens

When hyphens appear near the end of a line, they can cause unsightly word breaks. To address this issue and maintain browser compatibility, consider using the non-breaking hyphen character, ‑.

Example:

The text "3-3/8"" when rendered in HTML as "3-3/8”" experiences line breaks at the hyphen.

Previous Attempts:

Inserting the "zero width no break character", , proved ineffective.

Solution:

Simply replace the regular hyphen with the non-breaking hyphen character, ‑.

Usage:

To prevent line breaks after specific hyphens, insert ‑ in place of the hyphen. This character acts like a regular hyphen but prevents line breaks.

Browser Compatibility:

The non-breaking hyphen is supported in all major browsers, including Safari.

Note:

This solution applies to specific instances where line breaks after hyphens are undesirable. It's not intended as a global solution for entire pages.

The above is the detailed content of How Can I Prevent Unwanted Line Breaks After Hyphens in HTML?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template