-1

I have something like:

<div id="5.5a">
    <p >First Div</p>
</div>

and my CSS has:

#5.5a { 
    color=blue;
}

Shouldn't the id="5.5a" link to my CSS #5.5a? (Other parts of CSS work so my tag is right)

TylerH
  • 19,065
  • 49
  • 65
  • 86
BD N
  • 3
  • 2

2 Answers2

2

CSS requires colons, not equals signs:

#yourIDname {
    color: blue;
}

Further, IDs CANNOT start with numbers. See this answer for more info.

I think it is technically OK to have decimals in IDs, but you probably want to avoid them, because they are invalid for class names, and you run the risk of confusing #5.5a for ID 5 with child class 5a.

Community
  • 1
  • 1
TylerH
  • 19,065
  • 49
  • 65
  • 86
2

An id, like a class, in CSS should not start with a numeric character (it can, if you want, but it needs to be appropriately escaped) and cannot have a . in its id, since the . indicates that the following sequence of (valid) characters is a new class-name.

Further, the property-value assignment in CSS is to use a colon (:) not an equals (=):

That said, if you must use it as-is:

#\35\.5 {
  color: blue;
}
<span id="5.5">Demo</span>
David says reinstate Monica
  • 230,743
  • 47
  • 350
  • 385
  • I think the dot just would have to be escaped like any other “special” character, then it should work. – CBroe Oct 07 '14 at 18:21
  • For reference: http://www.w3.org/TR/html4/types.html#type-id "ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".")" – CodingWithSpike Oct 07 '14 at 18:21