1

A WP theme I am amending has 5 columns, all 5 have a class of span3 mbtm feature, but they also have classes of first, 0.25, 0.5, 0.75 and last respectively.

I only want to add CSS to the middle column, how do I target a class that begins with a number?

Adrian
  • 285
  • 2
  • 14
  • have you tried adding a class to the HTML template? – Cubius Apr 05 '14 at 11:09
  • 1
    possible duplicate of [CSS classes with names that start with numbers](http://stackoverflow.com/questions/21227702/css-classes-with-names-that-start-with-numbers) – Jukka K. Korpela Apr 05 '14 at 12:10
  • @JukkaK.Korpela Thank you, so would a class of 0.5, i presume the . is a whitespace character, what would the CSS selector be please, its a bit confusing, thank you. – Adrian Apr 05 '14 at 14:10
  • The period is not whitespace, but since it has a special meaning in CSS, it needs to be escaped when it is part of a class name. For `class=0.5`, a suitable selector is `.\30\.5`. The `\30` is escape for digit zero, and `\.` is escape for the period. – Jukka K. Korpela Apr 05 '14 at 14:37

2 Answers2

2

Check this excellent article by ben frain on the topic: http://benfrain.com/when-and-where-you-can-use-numbers-in-id-and-class-names/

Your css should look like

div[class=0.5] {
    background-color: #0f0; 
}

Although you can escape the characters, imo you should not use it for the sake of readability.

alpipego
  • 3,223
  • 2
  • 17
  • 28
0

Got to it using parent > div:nth-of-type(3)

Adrian
  • 285
  • 2
  • 14