Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
Force two words to be always together in a line

I have this line:

Welcome to the nicest home ๐Ÿš€

This line is inside a flex div width responsive width. When with is small enough, this happens

Welcome to the
nicest home 
๐Ÿš€

Is there a way with which I can force home and ๐Ÿš€ to be always together? So in the example I would get

Welcome to the
nicest
home ๐Ÿš€
almost 4 years ago ยท Santiago Trujillo
2 answers
Answer question

0

As suggested in the comments, a non-breaking space will do the trick.

To include it in the HTML, we usually use the symbol code:  

(Drag the corner of the box to resize and test the example)

div {
  display: block;
  resize: both;
  overflow: hidden;
  border: 1px solid #000;
}
<div>Welcome to the nicest home&nbsp;๐Ÿš€</div>

almost 4 years ago ยท Santiago Trujillo Report

0

One method to achieve this would be to replace the last whitespace found in the string with a non-breaking space entity, &nbsp;.

You can use JS to do this to all elements you decorate with a given class:

document.querySelectorAll('.no-orphans').forEach(el => {
  el.innerHTML = el.innerHTML.replace(/ (?=[^ ]*$)/i, "&nbsp;");
});
p { width: 100px; }
<p>Original:<br />Welcome to the nicest home ๐Ÿš€</p>

<p class="no-orphans">Corrected:<br />Welcome to the nicest home ๐Ÿš€</p>

The only caveat here is that the end of the content within the .no-orphans element cannot be a HTML element, only a text node

almost 4 years ago ยท Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!