JSFiddle - React, Tailwind, and code Playground
HTML
<div class="item gray">
<span>to jest zielony tekst</span>
</div>
CSS
.item {
width: 200px;
height: 200px;
text-align: center;
position: relative;
z-index: auto;
}
.item::before {
content: "";
position: absolute;
background: red;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
z-index: -1;
}
.item.gray::before {
filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale"); /* Firefox 10+, Firefox on Android */
filter: gray; /* IE6-9 */
-webkit-filter: grayscale(100%); /* Chrome 19+, Safari 6+, Safari 6+ iOS */
}
span {
line-height: 200px;
color: green;
}
JavaScript
$('.item').on('click', function () {
$(this).toggleClass('gray');
});