Reputation: 7232
I have a span with a text:
<span class="magic">a sample text</span>
is it possible to create selector that will change the color of every symbol 'a' or ' '
.magic...<something> {
color: red;
}
note: I do not want to surround every character with additional span - I know this will work
Upvotes: 4
Views: 3861
Reputation: 2216
There's no way to do this with CSS only, since it doesn't provide any selectors for this. Fortunately you can use javascript and regex instead.
Here's a example of jquery code that will replace every "a" character that's inside a p
element with <span class="red">a</span>
so it can be styled differently (I found this code somewhere here, in stackoverflow, and adapted it to your needs):
$('p').html($('p').html().replace(/a/g, '<span class="red">a</span>'));
Upvotes: 6
Reputation: 70
It's not possible with CSS, I've actually been looking for something quite similair. This is what I found a short while back: (jQuery plugin)
http://bartaz.github.io/sandbox.js/jquery.highlight.html
You can start with certain characters highlighted upon pageload... The documentation provided is not that hard to follow if you have some expecience.
Upvotes: 0