How can I prevent line breaks between words and punctuation in CSS or jQuery

I have a text in a paragraph. My problem is that when punctuation is at the end of a word, it can sometimes be wrapped on the next line. Like this:

This is the text , This is a new line 

Is it possible to resolve this with CSS or jQuery?

+4
source share
2 answers

If you do not put a space between the word and punctuation and that it is wrapped anyway, you can use the white-space: nowrap; css . Otherwise, if you need a space between a word and punctuation, as before ? , use non-breaking space code. You can get it by typing alt + 0160 on the keyboard if you are using Windows. For more keyboard methods read this .

Hope this helps.

+3
source

Suppose your problem goes up due to some space character before the comma, for example ... text , This ... when it should be ... text, This ....

At least this is the only reason I see. If you look at this script, you will find that the text in the third <p> will never be wrapped, as you mentioned. (you may need to choose a different width for your browser. The example above works in Chrome, but for the width of Firefox is slightly different)

So, just make sure you have no spaces between the text and the comma.

0
source

All Articles