0

Is it possible to set a conditional for the h2 text of a class? the h2 does not have a unique class or id to it, and multiple h2's with a dynamic changing order. So i can't target say the 3rd h2 because its always shifting.

h2.arker.fun.header {
// some statement If h2 text = "Gamer" then set text-transform: lowercase
}
acctman
  • 4,229
  • 30
  • 98
  • 142

3 Answers3

2

There was once proposed one pseudo class known as :contains to handle this situation. But they haven't added it yet in the current draft of CSS3.

However you may use some Javascript. For Example to deal with this problem

for (var i= document.links.length; i-->0;){
    if (/\bSpecificWord\b/i.test(document.links[i].innerHTML)
        document.links[i].style.color= 'red'; }

Hope you are not restrained from using Javascript.

YourFriend
  • 434
  • 4
  • 7
0

As others (@Paulie_D, @Mia Marks, @YourFriend) have already pointed out, there is no CSS < 4 selector based on content and the closest you can get is the attribute selector.

Just a crazy idea:

h2.arker.fun.header:before {
  content: attr(data-text);
}

h2.arker.fun.header[data-text="Gamer"] {
  text-transform: lowercase;
}
<h2 class="arker fun header" data-text="Gamer"></h2>

don't do it at home...

coma
  • 16,429
  • 4
  • 51
  • 76
-2

u can add attribute in that h2 tag and put the condition like: h2[if='mytype']{text-transform:lowercase;}