Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda