I am looking to incorporate dot leaders after the first line of text using CSS so that it can be used over a texture or image background.
Expected behavior:
https://i.sstatic.net/6Jsrk.png
I have come across a few implementations of dot leaders on the internet. They all utilize one of the following techniques:
- ::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;
}
All these methods are demonstrated here: https://jsfiddle.net/rzmLg4yu/62/
However, each technique has its drawbacks in my particular scenario.
- Dot leaders appear at the last line.
- It does not function well over complex backgrounds, even with mix-blend-mode (uncomment bg line to see). https://i.sstatic.net/lfk1j.png
- There are significant white gaps due to line breaks (resize to view). Transitioning to grid layout does not solve the issue. https://i.sstatic.net/KK4vj.png
Are there any other solutions to address this problem?