在CSS中使用:before伪类插入特殊字符
我正在摆弄 css 中的 :before
伪类,试图插入一个特殊字符,但结果不是我所希望的。
使用:
.read_more:before {
content: "»";
margin-right: 6px;
}
我得到了我想要的字符,但在它之前有一个 â 字符并使用:
.read_more:before {
content: "»";
margin-right: 6px;
}
我在 html 页面上得到了完整的 »
。
我可以想出几种方法来解决我的问题,但我想知道如果我想使用 :before
伪类,正确的语法是什么。
顺便说一句,我的文档类型是:
<!doctype html>
<html lang="en">
I was toying around with the :before
pseudo class in css, trying to insert a special character but the result is not what I was hoping for.
Using:
.read_more:before {
content: "»";
margin-right: 6px;
}
I get the character I want, but with an  character before it and using:
.read_more:before {
content: "»";
margin-right: 6px;
}
I get the complete »
on the html page.
I can think of a couple of ways to solve my problem, but I was wondering what the correct syntax would be if I wanted to use the :before
pseudo class.
By the way, my doctype is:
<!doctype html>
<html lang="en">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
试试这个
\00BB 是该字符的 unicode 表示形式。它应该合理地工作=)
try this
\00BB is the unicode representation of that character. It should reasonably works =)
答案已经告诉了,但我想参考一下:
这是因为 CSS
content
属性不被视为 HTML。它不会附加到 DOM,因此不会解析任何特定于 HTML 的标记。您可以直接插入字符:content: "";
或使用 Unicode 表示法:content: "\0504";
。The answer has been already told, but I want to refer to:
That's because CSS
content
property isn't treated as HTML. It's not appended to the DOM, therefore any HTML-specific markup isn't parsed. You can insert a character directly:content: "Ԃ";
or use Unicode notation:content: "\0504";
.尝试指定
。理想情况下,您希望在服务器中进行设置。
Try specifying
<meta charset="utf-8">
. Ideally you want to set this in the server.我知道自从提出这个问题以来已经有一段时间了,但如果现在有人可能需要它,我找到了解决方案。
这里有一个包含大量字形的图表。找到您想要的并复制它的十六进制代码。
然后将其粘贴到此处进行转换。
您将得到一个如下所示的值:\00E1(CSS 值)
将此值粘贴到您的“内容:”上并感到高兴:)
I know it's been a while since this question was asked but in case someone might need it nowadays, I found the solution for it.
Here's a chart with lots of glyphs. Find the one you want and copy the hex code for it.
Then paste it here to convert.
You'll get a value that looks like this: \00E1 (CSS Value)
Paste this value on your 'content:' and be happy :)
您的浏览器没有使用正确的文本编码——也就是说,它没有使用与您的编辑器相同的文本编码。如果您从 Web 服务器接收页面,最好的方法是确保服务器发送正确的 Content-Type 标头。如果您无法控制 Web 服务器的标头,或者您将使用本地 HTML 文件进行大量测试,请添加 针对您所使用的编码和 HTML 版本的文档添加适当的标签。我建议使用 UTF-8。 CSS 文件(如果它与 HTML 分开)应使用相同的编码。
Your browser isn't using the correct text encoding -- that is, it isn't using the same text encoding as your editor. If you are receiving the page from a Web server, the best approach is to make sure the server is sending the proper Content-Type header. If you don't have control over the Web server's headers, or if you will be doing a lot of testing using local HTML files, add appropriate tags to your document for the encoding and HTML version you are using. I recommend using UTF-8. The CSS file (if it is separate from the HTML) should use the same encoding.
将其添加到 html 的
部分中
但是如果 html 页面是用 PHP 编码的,我会更喜欢以下内容:
并且不要忘记保存任何文件(css、html、 php) 使用 UTF-8 编码
Add this on the html, inside the
<head>
sectionBut if the html page is coded in PHP, I would prefer the following:
And don't forget to save any file (css, html, php) with UTF-8 encoding