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

发布于 2024-10-26 15:23:35 字数 757 浏览 3 评论 0原文

我有以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

捶死心动 2024-11-02 15:23:35

使用反斜杠。

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

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

jsFiddle 演示

Use a backslash.

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

Same goes for single quotes within single-quoted strings.

jsFiddle demo

你的笑 2024-11-02 15:23:35

只需使用 \ 转义 "

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

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

Just use a \ to escape the "

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

Demo @ http://jsfiddle.net/NaEPq/4/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文