A dash that prevents line breaks between two words

Is there a way to have a dash (-) that won't break the word if it ends the line? (Just like   prevents line breaks between two words)

The problem I am having right now is a blog post (dynamic) that has the word X-Ray in it. Unfortunately, it falls to the end of the line, so I get

 Lorem ipsum dolor si amet X- Ray 

I would like to prevent this and get such a result

 Lorem ipsum dolor si amet X-Ray 

I canโ€™t just <br /> everything, because depending on where you are on the website, it will not get stuck in this position everywhere.

+6
source share
4 answers

Try to break the hyphen, &#8209;

Information at http://www.fileformat.info/info/unicode/char/2011/index.htm

+5
source

You can use the Unicode Hypene Unicode character (U + 2011) .

 HTML Entity (decimal) &#8209; HTML Entity (hex) &#x2011; How to type in Microsoft Windows Alt +2011 UTF-8 (hex) 0xE2 0x80 0x91 (e28091) UTF-8 (binary) 11100010:10000000:10010001 UTF-16 (hex) 0x2011 (2011) UTF-16 (decimal) 8,209 UTF-32 (hex) 0x00002011 (2011) UTF-32 (decimal) 8,209 C/C++/Java source code "\u2011" Python source code u"\u2011" 
+4
source

The most widely used method is <nobr>X-ray</nobr> . Although not part of the HTML specification, the nobr tag works well.

Currently, using the inextricable hyphen U + 2011 (suggested in other answers, you can also enter it directly if you know how to do this in your editor, and you use UTF-8) works almost as widely. However, there are risks. Support for U + 2011 is not universal in fonts. This means that if you do not take special measures to use the font that contains it, or to use suitable fallback fonts, it is possible that the inextricable hyphen differs from the usual hyphen (which is basically an โ€œAscii hyphenโ€ on web pages) .

This means that foo-bar and foo-bar (with an inextricable hyphen) may look different since they come from different fonts. In order to see the difference, you may need a trained eye or typographer, but in some font combinations the difference is obvious.

Using nobr , you do not have this problem as the same character is used. The same goes for using <span style="white-space: nowrap">X-ray</span> , but its a bit awkward and a little less reliable (doesn't work when CSS is disabled).

+1
source

This site will provide you with more information than you will ever need.

 &#8211; 

This is what you need.

-1
source

Source: https://habr.com/ru/post/924651/


All Articles