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

201
Views
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 answers
Answer question

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 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!