如何在 CSS 中转义单引号或双引号?
我有以下 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/
我的问题是,当我使用双引号时“我说过不要碰我”
,我收到警告。
CSS:
#notworking:hover:after{
content: ""I Said Don't Touch Me"";
color: #C30;
}
警告消息:
Warning: Found unclosed string '";'.
那么,如何在 CSS 中转义单引号或双引号呢?
I have the following HTML code:
<div id="working">Touch Me!</div>
<div id="notworking">Don't Touch Me!</div>
And I have this CSS:
#working:hover:after{
content: "Nice Touch";
color: #0C6;
}
#notworking:hover:after{
content: "I Said Don't Touch Me";
color: #C30;
}
This code is working fine (my example is here):
http://jsfiddle.net/gchoken/NaEPq/
My problem is that when I use double quotes for "I Said Don't Touch Me"
, I get a warning.
CSS:
#notworking:hover:after{
content: ""I Said Don't Touch Me"";
color: #C30;
}
Warning message:
Warning: Found unclosed string '";'.
So, how exactly can I escape single or double quotes in CSS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用反斜杠。
单引号字符串中的单引号也是如此。
jsFiddle 演示
Use a backslash.
Same goes for single quotes within single-quoted strings.
jsFiddle demo
只需使用
\
转义"
演示 @ http: //jsfiddle.net/NaEPq/4/
Just use a
\
to escape the"
Demo @ http://jsfiddle.net/NaEPq/4/