使用 CSS 内容添加 HTML 实体
如何使用 CSS content
属性添加 HTML 实体?
使用类似的东西只会将
打印到屏幕上,而不是不间断的空格:
.breadcrumbs a:before {
content: ' ';
}
How do you use the CSS content
property to add HTML entities?
Using something like this just prints
to the screen instead of the non-breaking space:
.breadcrumbs a:before {
content: ' ';
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
更新:PointedEars 提到在所有 css 情况下
的正确替代是
'\a0 '
表示空格是十六进制字符串的终止符,并被转义序列吸收。 他进一步指出这个权威描述听起来像是一个很好的解决方案我在下面描述和解决的问题。您需要做的是使用转义的 unicode。 尽管您被告知
的完美替代品; 所以尝试:
\00a0
并不是 CSS 中具体使用
。
\0000a0
作为如果您尝试,按照 mathieu 和 millikin 的建议:
它将 B 放入十六进制转义字符中。 0-9a-fA-F 也会发生同样的情况。
Update: PointedEars mentions that the correct stand in for
in all css situations would be
'\a0 '
implying that the space is a terminator to the hex string and is absorbed by the escaped sequence. He further pointed out this authoritative description which sounds like a good solution to the problem I described and fixed below.What you need to do is use the escaped unicode. Despite what you've been told
within CSS; so try:
\00a0
is not a perfect stand-in forSpecifically using
.
\0000a0
asIf you try, as suggested by mathieu and millikin:
It takes the B into the hex escaped characters. The same occurs with 0-9a-fA-F.
在 CSS 中,您需要使用 Unicode 转义序列来代替 HTML 实体。 这是基于字符的十六进制值。
我发现将符号转换为十六进制等价物的最简单方法是使用 Microsoft 计算器 = )
是的。 启用程序员模式,打开十进制,输入
9662
,然后切换到十六进制,你会得到25BE
。 然后只需在开头添加一个反斜杠\
即可。In CSS you need to use a Unicode escape sequence in place of HTML Entities. This is based on the hexadecimal value of a character.
I found that the easiest way to convert symbol to their hexadecimal equivalent is, such as from ▾ (
▾
) to\25BE
is to use the Microsoft calculator =)Yes. Enable programmers mode, turn on the decimal system, enter
9662
, then switch to hex and you'll get25BE
. Then just add a backslash\
to the beginning.使用十六进制代码作为不间断空格。 像这样的东西:
Use the hex code for a non-breaking space. Something like this:
有一种方法可以粘贴
nbsp
- 打开 CharMap 并复制字符 160。 但是,在这种情况下,我可能会用填充将其隔开,如下所示:不过,您可能需要设置面包屑
display:inline-block
或其他内容。There is a way to paste an
nbsp
- open CharMap and copy character 160. However, in this case I'd probably space it out with padding, like this:You might need to set the breadcrumbs
display:inline-block
or something, though.例如:
http://character-code.com/arrows-html-codes.php< /a>
示例:如果你想选择你的角色,我选择了“↬”“↬”(我们使用十六进制值)
结果:↬
就是这样:)
For Example :
http://character-code.com/arrows-html-codes.php
Example: If you want select your character , I selected "↬" "↬" (We use HEX values)
Result: ↬
Thats it :)
我知道这是一篇相当老的文章,但如果间距是您的全部,为什么不简单地:
我以前使用过这种方法。 它用“>”完美地包裹到其他行 在我的测试中。
I know this is an pretty old post, but if spacing is all your after, why not simply:
I have used this method before. It wraps perfectly fine to other lines with ">" by its side in my testing.
这里有两种方法:
在 HTML 中:
⛱
这将导致
⛱
在 CSS 中:
.ics::before {content: "\9969;"}
和 HTML 代码
这也会导致 ⛱
Here are two ways:
In HTML:
<div class="ics">⛱</div>
This will result into
⛱
In Css:
.ics::before {content: "\9969;"}
with HTML code
<div class="ics"></div>
This also results in ⛱
只是为了让这里的答案更完整一些。 如果您使用类似
content: attr(aria-label);
的内容,那么您不需要使用 unicode 转义,而是需要使用 HTML 实体。 例如,使用生成换行符。
Just to make the answers here a little more complete. If you are using something like
content: attr(aria-label);
, then rather than using unicode escapes, you DO need to use HTML entities instead. For example, usingto generate a line break.
你必须使用转义的unicode:
像
You have to use the escaped unicode :
Like
CSS 不是 HTML。
是一个命名的字符引用< /a> 在 HTML 中; 相当于十进制数字字符引用
。 160 是 Unicode< 中
NO-BREAK SPACE
字符的十进制代码点 /a> (或 UCS-2;请参阅 HTML 4.01 规范)。 该代码点的十六进制表示为 U+00A0 (160 = 10 × 161 + 0 × 160)。 您会在 Unicode 代码图表 和 角色数据库。在 CSS 中,您需要对此类字符使用 Unicode 转义序列,该序列基于字符代码点的十六进制值。 您就需要这样写
因此,只要转义序列出现在字符串值的最后, 。 如果后面有字符,有两种方法可以避免误解:
a) (其他人提到过)使用 6 个十六进制数字作为转义序列:
b) 在转义序列后面添加一个空白(例如空格)字符:
(Since < code>f 是一个十六进制数字,
\a0f
在此表示GURMUKHI LETTER EE
,如果您有合适的字体,则表示 ਏ。)空格将被忽略,并且将显示
foo
,其中显示的空格将是NO-BREAK SPACE
字符。与六位数字方法 (
'\0000a0foo'
) 相比,空白方法 ('\a0 foo'
) 具有以下优点:因此,要在转义字符后显示空格,请在样式表中使用两个个空格 -
或者使其明确:
请参阅CSS 2.1,“4.1.3 字符和大小写”部分了解详细信息。
CSS is not HTML.
is a named character reference in HTML; equivalent to the decimal numeric character reference
. 160 is the decimal code point of the
NO-BREAK SPACE
character in Unicode (or UCS-2; see the HTML 4.01 Specification). The hexadecimal representation of that code point is U+00A0 (160 = 10 × 161 + 0 × 160). You will find that in the Unicode Code Charts and Character Database.In CSS you need to use a Unicode escape sequence for such characters, which is based on the hexadecimal value of the code point of a character. So you need to write
This works as long as the escape sequence comes last in a string value. If characters follow, there are two ways to avoid misinterpretation:
a) (mentioned by others) Use exactly six hexadecimal digits for the escape sequence:
b) Add one white-space (e. g., space) character after the escape sequence:
(Since
f
is a hexadecimal digit,\a0f
would otherwise meanGURMUKHI LETTER EE
here, or ਏ if you have a suitable font.)The delimiting white-space will be ignored, and this will be displayed
foo
, where the displayed space here would be aNO-BREAK SPACE
character.The white-space approach (
'\a0 foo'
) has the following advantages over the six-digit approach ('\0000a0foo'
):Thus, to display a space after an escaped character, use two spaces in the stylesheet –
– or make it explicit:
See CSS 2.1, section "4.1.3 Characters and case" for details.