Has anyone come up with a good solution to ensure that an icon is always next to the word preceding it (i.e., it never wraps to the next line)?
Run the code snippet below to see the problem...
div {
width: 52ch;
}
img {
width: 16px;
height: 16px;
}
<div>
The next sentence has a multi-word link where the (i) icon should always be next to the word "link".
This is a <a href="#">sample link<img src="https://www.svgrepo.com/show/20745/info.svg"></a>.
</div>
The goal is to always keep the (i) icon next to the word "link" so that it never becomes an orphan on the next line. If the sentence needs to wrap, then "link(i)" should wrap together as one unit.
Restrictions that I have no control over:
I cannot do this because I'm not able to manipulate the DOM (this would have to be a pure CSS solution):
<a href="#">sample <span class="no-wrap">link<img src="https://www.svgrepo.com/show/20745/info.svg"></span></a>
I cannot use pseudo elements like
::before
and::after
to render the icon because the icon can be after any word in the link, not necessarily the last word.
UPDATE: Thank you everyone who tried to help. They closed this as a duplicate, even though it's not a duplicate since the question was not about how to "stop text from taking up more than 1 line". This is taking up more effort than it's worth, so instead of trying to get this reopened I'm going to keep it closed and just accept that sometimes the icon will not be next to the preceding word. It's not aesthetically pleasing, but not the end of the world.