Reputation: 3
I want to render some text, like from <span class="divided">ABCD</span>
to A | B | C | D
.
' | '
should not be rendered as a normal text because it would lower the screen-reader accessibility.
Maybe I could do this with JavaScript, like
<span class="divider">
,
where .dividier:not(:last-child)::after { content: ' | '; }
But I think it's not a good way. I don't want to change the html itself.
Would it be possible only with CSS?
Upvotes: 0
Views: 58
Reputation: 272901
A CSS-only idea but you will need a monospace font
.divided {
font-family: monospace;
font-size: 50px;
letter-spacing: 10px;
background:
repeating-linear-gradient(90deg,#000 0 3px,#0000 0 calc(1ch + 10px))
-6.5px 50%/100% 80% no-repeat;
/*-6.5px = -(5 + 1.5) half the letter-spacing + 3px
1ch = width of one letter
3px = width of the seperator
80% = height of the seperator
*/
}
<span class="divided">ABCD</span>
Upvotes: 0
Reputation: 8610
Using javascript you can use .split('')
and split the string into and array of characters, then use .join(' | ')
to join the array back together into a string with the desired characters.
el.textContent.split('').join(' | ');
let divided = document.querySelector('.divided');
divided.textContent = divided.textContent.split('').join(' | ');
<span class="divided">ABCD</span>
Upvotes: 1