As we mentioned, CSS doesn’t have a selector that lets you match text. You could do it in CSS by adding classes to all of the elements that contain the text you don’t want to style, but that requires the HTML to be changed.
You ask in a comment if this could be done using jQuery - it can, using a combination of the contains
and not
selectors.
Using jQuery also means you don’t don’t have to change the existing HTML.
The easiest way is to first create a CSS class with the styles to apply, e.g.
.shadow {
font-weight: inherit;
filter: drop-shadow (0px 0px 0rem black);
box-shadow: 0px 0px 0px black
}
Now you can use JQuery to select all spans that do not contain “dontwant” and add your class to them, like this:
$('span:not(:contains("dontwant"))').addClass('shadow');
You just add this line to your $(document).ready(function()
Working Snippet:
$('span:not(:contains("dontwant"))').addClass('shadow');
.shadow {
font-weight: inherit;
filter: drop-shadow(0px 0px 0rem black);
box-shadow: 0px 0px 0px black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<p>This is a span I <span>dontwant</span> to add <span>shadow</span>.</p>
<p>This is <span>another</span> span I <span>dontwant</span> to add <span>shadow</span>.</p>
You can include this in Angular in the ngOnInit
function, e.g.:
public ngOnInit(){
$(document).ready(function(){
$('span:not(:contains("dontwant"))').addClass('shadow');
});
}