CSS“内容”属性中的换行符序列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9062988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Newline character sequence in CSS 'content' property?
提问by Saeed Neamati
Is it possible to use newlinecharacter in CSS content
property to force a line break? Something like:
是否可以在 CSS属性中使用换行符content
来强制换行?就像是:
figcaption:before
{
content: 'Figure \n' + attr(title);
}
回答by Jukka K. Korpela
figcaption:before
{
content: 'Figure \a' attr(title);
white-space: pre;
}
Note that in the content
attribute value, concatenation is expressed just by whitespace, not by a “+” sign. The escape notation \a
in a CSS string literal indicates a linebreak character.
请注意,在content
属性值中,连接仅由空格表示,而不是由“+”号表示。\a
CSS 字符串文字中的转义符号表示换行符。
回答by álvaro González
The contentproperty accepts a stringand:
A string cannot directly contain a newline. To include a newline in a string, use an escape representing the line feed character in ISO-10646 (U+000A), such as "\A" or "\00000a". This character represents the generic notion of "newline" in CSS.
字符串不能直接包含换行符。要在字符串中包含换行符,请使用表示 ISO-10646 (U+000A) 中换行符的转义符,例如“\A”或“\00000a”。这个字符代表了 CSS 中“换行符”的通用概念。
(No idea about actual browser support.)
(不知道实际的浏览器支持。)
You can check Using character escapes in markup and CSSfor reference about the escape syntax, which essentially is:
您可以查看在标记和 CSS 中使用字符转义以获取有关转义语法的参考,其本质上是:
\20AC
must be followed by a space if the next character is one of a-f, A-F, 0-9\0020AC
must be 6 digits long, no space needed (but can be included)
\20AC
如果下一个字符是 af、AF、0-9 之一,则必须后跟一个空格\0020AC
必须是 6 位数字,不需要空格(但可以包含)
NOTE: use \00000a
rather than just \A
when escaping an arbitrary string, because if the newline is followed by a number or any character from [a-f]
range, this may give an undesired result.
注意:使用\00000a
而不仅仅是\A
在转义任意字符串时,因为如果换行符后跟数字或[a-f]
范围内的任何字符,这可能会产生不希望的结果。