I need to implement dot leaders after first line of text using CSS to use it over texture/image background.
Expected behaviour:
I saw a few implementation of dot leaders over the internet. They all use one of the techniques below:
- ::after dots + overflow
<div class=item1>
<span class=text1>
Text
</span>
<span class=price1>
$100
</span>
</div>
.item1 {
display: flex;
}
.text1 {
flex-grow: 1;
position: relative;
overflow: hidden;
}
.text1::after {
content: '';
position: absolute;
bottom: 0;
border-bottom: 1px dotted grey;
width: 100%;
}
.price1 {
align-self: flex-end;
}
- absolute dots + white background
<div class=item2>
<span class=text2>
<span class=bg2>
Text
</span>
</span>
<span class=price2>
<span class=bg2>
$100
</span>
</span>
</div>
.item2 {
display: flex;
justify-content: space-between;
position: relative;
mix-blend-mode: darken;
}
.item2::before {
content: '';
position: absolute;
top: 1em;
left: 0;
right: 0;
border-bottom: 1px grey dotted;
}
.bg2 {
background: white;
position: relative;
z-index: 1;
}
- dumb flexbox
<div class=item3>
<span class=text3>
Text
</span>
<span class=dots3></span>
<span class=price3>
$100
</span>
</div>
.item3 {
display: flex;
align-items: flex-start;
}
.dots3 {
flex-grow: 1;
border-bottom: 1px dotted grey;
min-width: 10px;
height: 1em;
}
They are all shown here: https://jsfiddle.net/rzmLg4yu/62/
Each of these techniques has its own pitfalls in my case.
- Has dot leaders at last line.
- Does not work over complex background, even with mix-blend-mode (uncomment bg line to see).

- Has large white gaps due to line breaks (resize to see). Switching to grid is no use.

Is there more solutions to this case?

