Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ensure two words stay on the same line?

I am making a person website for myself. In my short bio, I have a few words (or groups of words) that are highlighted. In some of my testing, I have noticed that sometimes two words get split, so the highlighting effect looks like crap.

Here's a picture of what it should look like, and what it looks like if the font changes, respectively:

Should Look Like

Don't want this happening

Notice how "web developer" get's pushed apart to two lines. Is there any way I can ensure they stay together?

like image 335
Adam Bowker Avatar asked Dec 05 '13 20:12

Adam Bowker


People also ask

How do you put all words on one line?

You need a “soft hyphen” a.k.a. “nonbreaking hyphen.” To put one of those babies in, just delete the hyphen you already have and, with your cursor still in place between the words you want hyphenated, press CTRL-SHIFT-HYPHEN (yes, that's all at the same time, so you'll need a little coordination to pull this off).


2 Answers

Just apply a non-breaking space ( ) between the two words:

word1 word2

This is especially useful when it comes to french punctuation and numbers

If you need this on a larger scale then you can use CSS:

div {
  white-space: nowrap;
}
<div>word 1 word2 word3</div>

You would have to use this method if you are trying to make sure text and a svg stay together on the same line, non-breaking space does not work for that.

You can create a nowrap class so you can apply it anywhere:

<span class="nowrap">No one can wrap us</span>
like image 153
Huangism Avatar answered Oct 05 '22 07:10

Huangism


The CSS way:

a { white-space: nowrap; }
like image 23
Geomatic Avatar answered Oct 05 '22 07:10

Geomatic