如何在CSS中转义单引号或双引号?

时间:2011-03-25 04:46:00

标签: html css parsing escaping quotes

我有以下HTML代码:

<div id="working">Touch Me!</div>
<div id="notworking">Don't Touch Me!</div>

我有这个CSS:

#working:hover:after{
    content: "Nice Touch";
    color: #0C6;
}
#notworking:hover:after{
    content: "I Said Don't Touch Me";
    color: #C30;
}   

此代码工作正常(我的示例在这里): http://jsfiddle.net/gchoken/NaEPq/

我的问题是,当我使用"I Said Don't Touch Me"的双引号时,我会收到警告。

CSS:

#notworking:hover:after{
    content: ""I Said Don't Touch Me"";
    color: #C30;
}  

警告讯息:

Warning: Found unclosed string '";'.

那么,我怎样才能在CSS中转义单引号或双引号?

2 个答案:

答案 0 :(得分:13)

使用反斜杠。

content:"i said don\"t Touch me";

单引号字符串中的单引号也是如此。

jsFiddle demo

答案 1 :(得分:3)

只需使用\即可转义"

#notworking:hover:after{
    content:"i said don\"t Touch me";
        color: #C30;
} 

演示@ http://jsfiddle.net/NaEPq/4/