【问题标题】:How can I escape single or double quotation marks in CSS?如何在 CSS 中转义单引号或双引号?
【发布时间】:2011-07-22 16:01:12
【问题描述】:

我有以下 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 中转义单引号或双引号?

【问题讨论】:

    标签: html css parsing escaping quotes


    【解决方案1】:

    使用反斜杠。

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

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

    jsFiddle demo

    【讨论】:

      【解决方案2】:

      只需使用\ 转义"

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-08
        • 2011-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多