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

200
Visualizações
Break text surrounded by other elements in the same line

I'm trying to display 3 DOM elements in a row. The 1st and the 3rd ones are divs with constant width and height, the one in the middle is text and can grow. The height of 1 and 3 has to be equal to the height of a single line of text.

Elements Arrangement

The problem begins when the text element grows long. I'd want like to display 1 before the first line of text and 3 right where the text ends.

Some other arrangement

The combination of two changes helped me to achieve this:

  1. I set flex-wrap: wrap for parentContainer
.parentContainer {
    display: flex;
    flex-direction: row;        
    flex-wrap: wrap;
}
  1. I wrapped each word into its own <span>...</span>

enter image description here

Although this approach displays the elements correctly, I have two problems with it

  1. Instead of using Unicode line breaking algorithm I have to break text into words myself. The text is not guaranteed to have any whitespaces, unfortunately.

  2. Double mouse click only selects text within a single span instead of the entire text.

I wonder if there is a different approach to it that isn't prone to the issues described above?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I think the key to achieving this might be to use css to set the display property of the icons/divs to inline. You may have to play with sizes to get things how you want them but making the image an inline element allows you treat it as if it were just another word.

In this example, I linked an image to simulate your bounding elements.

    img {
    width: 30px;
    aspect-ratio: 1;
    display: inline;
    vertical-align: middle;
    }
<img src="https://stackoverflow.design/assets/img/logos/sf/sf-icon.svg" />  text text here text here more text here even more text here text here more text here even more text<img src="https://stackoverflow.design/assets/img/logos/sf/sf-icon.svg" />

about 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