Reputation: 3984
Is there a way using pure CSS to replace part of content text, for example if the text is ABCDE
-
<span class="replacer">ABCDE</span>
But instead of ABCDE
the first 3 chars will be *
so it will displayed as ***DE
.
Upvotes: 1
Views: 11707
Reputation: 123397
No, in pure CSS it's not possible to change the content, but you could cheat by overlapping something, e.g.
.replacer {
font-family: monospace;
position: relative; }
.replacer::before {
background: #fff;
position: absolute;
content: "***";
}
or, another tricky way could be creating and loading a special font that maps the symbols A
, B
and C
into the asterisk sign (through the unicode-range
property, https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range)
in javascript you would only need to replace the textContent
property of the element
var el = document.getElementsByClassName('replacer')[0]
el.textContent = el.textContent.replace(/^.{3}/, '***');
Upvotes: 5
Reputation:
.replacer {
display: inline-block;
position: relative;
font-family:monospace;
font-size:18px;
}
.replacer:before {
content: attr(stars);
background-color: #fff;
position: absolute;
left: 0;
}
<span stars="***" class="replacer">ABCDE</span>
To increase the number of stars in beginning, just change the stars attribute in html, similarly same can be done for .replacer::after
, see example below
.replacer {
display: inline-block;
position: relative;
font-family:monospace;
font-size:18px;
}
.replacer:after {
content: attr(stars);
background-color: #fff;
position: absolute;
right : 0;
}
<span stars="***" class="replacer">ABCDE</span>
Upvotes: 5