Thursday

Escaping numeric classnames

Though not something I tend to use often, occasionally I've had to wrangle classnames that either were totally numeric, or just started with a number (e.g. "4star" for a hotel rating). Numeric classnames are valid, however selecting them in your CSS requires character escaping. For example, to style this span:
Some Average 4 Star Hotel
I would need to escape the number "4" with a "\3", like so:
.\34star {color:red};
I read somewhere that (oddly) IE doesn't mind numeric classes, but I've found that unless I escape my selector with "\3", the various browsers won't select my element.

NOTE

IDs can't start with a number; classes can, but IDs cannot - they won't work.

No comments:

Post a Comment