Tuesday, August 03, 2010

The Backward Slash: Escaping Reserved Characters in CSS

Let's say you have an id name with a period in your HTML:

<div id="box1.1">
August 3, 2010 is an overcast day
</div>

Although this won't create a problem in the markup, when you try to style it using the name box1.1, your styles won't work right since the period is a reserved character. It's best to avoid reserved characters in names but if you do use them then the correct way of referencing a name that includes a period is to escape the period with a backward slash.

#box1\.1 { 
     float: left; 
} 

Post a Comment

Note: Only a member of this blog may post a comment.