0

Here's a strange one. This seems pretty simple but just isn't working.

Fiddle

I have images within a container. Images with class="1" should take up the full width of the container div. Images with class="2" should be able to fit 2 images side by side, taking up the full width of the container div. Images with class="3" should be able to fit 3... you get the idea.

However, even though the classes are being applied (inspect the elements!), the styles are not. The only thing that seems to work is a general style for #container img, which Iyou can test in the fiddle by removing the ".1" or ".2" from either style. As soon as you add .1, the images no longer take on the style, even if they are class="1"!

All I can think tis that maybe tags don't support the class attr? But I don't think that's true.

GtwoK
  • 497
  • 4
  • 16
  • I believe the class names cannot start with a number. Try an alpha instead (i.e. a, b, c) – blurfus Mar 19 '15 at 17:16
  • 2
    HTML5 allows class names to begin with a number, however CSS does not allow selectors to begin with numbers. – jmoerdyk Mar 19 '15 at 17:17

2 Answers2

7

CSS class selectors cannot start with a number.

Use an attribute selector or (more sensibly) better class names.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

The problem is that

In CSS, identifiers [...] cannot start with a digit.

That means that class selectors can start with a digit, but you must escape it properly.

To escape a digit d, you can use \00003d or \3d  (note the whitespace).

For example,

.\31 {
  background: #0f0;
}
<div class="1">Foo bar</div>
Oriol
  • 274,082
  • 63
  • 437
  • 513