I have a small icon on at the end of a short paragraph of text, which may wrap over multiple lines depending on the viewport size. It’s important to me that this icon not occupy an empty line by itself, but rather carry the last word of the paragraph with it. Is there any way to ensure this with pure css?
I considered dynamically grouping the last word of the paragraph with the icon in an inline block. I would prefer to not have to use javascript though, if possible.
This jsfiddle displays the undesired behavior.
<div class="resizable">
<span>Lorem ipsum dolor sit amet</span>
<div class="inlineblock"> </div>
</div>
.resizable {
border: 1px solid black;
resize: both;
overflow: hidden;
width: 11.5rem;
}
.inlineblock {
width: 10px;
height: 10px;
background-color: blue;
display: inline-block;
}
3
Answers
You could use ::after to place the block
Change the html a bit by wrapping
.inlineblock
and the last word in<span>
which will havewhite-space: nowrap;
:As you have mentioned in a comment that the block should be clickable and trigger an event so I have written the following code for you. Here I have used anchor tag on purpose. But you can use a span as well.