Skip to content
Advertisement

How to make the span to fill empty space on current line and continue to show remaining text on next line

In the below code snippet example, after marked word science and theory there is a empty space at the end. Forcing the next span element to appear on the newline.

How to make the next span element after marked word to fill the empty space. and then the remaining words of that span should continue display on new line?

So that the whole text looks like a description with tagged words on it.

enter image description here

JavaScript

Advertisement

Answer

Remove display: flex from the outer <div> and use display: inline-flex; to make your span elements display inline like a <span>.

display: flex; makes the element display as a block element (i.e. it will behave like a <div> which is what you’re seeing).

Here is a simplified version of your markup showing where to make the change:

JavaScript

Updated to use inline-flex:

JavaScript

Here’s a runnable example:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement