[英]Why is there no letter-spacing between a nested inline element and a following character?
After reading the spec for letter-spacing, I understand that runs of atomic inlines (ex inline-block) elements are treated as a single character ( http://www.w3.org/TR/css3-text/#letter-spacing ): 阅读了字母间距规范之后,我了解到原子内联(例如,内联块)元素的运行被视为单个字符( http://www.w3.org/TR/css3-text/#letter-spacing ):
For the purpose of letter-spacing, each consecutive run of atomic inlines (such as image and/or inline blocks) is treated as a single character.
出于字母间距的目的,原子内联的每次连续运行(例如图像和/或内联块)都被视为单个字符。
In all browsers I tested (Chrome, Safari, Firefox, IE 9+10), it doesn't seem to work like this. 在我测试过的所有浏览器(Chrome,Safari,Firefox,IE 9 + 10)中,它似乎都无法正常工作。
The following code ( http://codepen.io/caleb/pen/CqDfK ): 以下代码( http://codepen.io/caleb/pen/CqDfK ):
<style>
div { letter-spacing: 2em; }
em { letter-spacing: normal; }
</style>
<div>
a<em>em</em><em>em</em>bc
</div>
is rendered like: 呈现为:
a ememb c
Is there a reason why there isn't an additional 2em of spacing between the emem
and the b
? 有没有理由在
emem
和b
之间没有额外的2em间距? Since the emem
is a single character. 由于
emem
是单个字符。
Perhaps the spec does not seem to be fully implemented as you comment, but I am not sure. 正如您所评论的那样,该规范似乎并未完全实现,但我不确定。 When I put in a modified version of the example from the spec (modified in that I made all inner elements
em
and changed sizes to see better; changes in quote below given in brackets)... 当我从规范中放入示例的修改版本时(修改后,我制作了所有内部元素
em
并更改了大小以更好地查看;下面引号中的更改在方括号中给出)...
For example, given the markup
例如,给定标记
<P>a<LS>b<Z>cd</Z><Y>ef</Y></LS>g</P>
and the style sheet
和样式表
LS [em] { letter-spacing: 1em; } Z [em > em] { letter-spacing: 0.3em; [made 3em in example] } Y [em > em + em] { letter-spacing: 0.4em; [made 6em in example]}
the spacing would be
间距将是
a[0]b[1em]c[0.3em]d[1em]e[0.4em]f[0]g
...it does not render according to what they state , which implies some variation to the spec. ...它并没有按照他们所说的进行渲染 ,这意味着对规范有一些变化。 Instead, the rule that appears to be followed is that the preceding letter's
letter-spacing
value determines the space that follows it. 取而代之的是, 似乎遵循的规则是前一个字母的
letter-spacing
值确定了其后的空格。 This might be an implementation based on the interpretation of this statement from the spec: 这可能是基于规范对以下语句的解释的实现:
At element boundaries, the total letter spacing between two characters is given by and rendered within the innermost element that contains the boundary.
在元素边界处,两个字符之间的总字母间距由包含边界的最里面的元素给定并呈现在其中。
But I am not sure of that. 但是我不确定。 At any rate, following what appears to be the rule the browser's are using, that the preceding letter's
letter-spacing
value determines the spacing, then that explains the answer to your question of 无论如何,下面这似乎是浏览器的使用规则,即前一字母的
letter-spacing
值确定的间距,然后解释回答你的问题
Is there a reason why there isn't an additional 2em of spacing between the emem and the b?
有没有理由在Emem和b之间没有额外的2em间距?
It is because the letter preceding the b
is the m
contained in a letter-spacing: normal
coded element, which gives a zero width spacing after it. 这是因为前面的字母
b
是m
包含在letter-spacing: normal
编码元件,其给出一个零宽度后间距。 I don't believe the reference... 我不相信这个参考...
For the purpose of letter-spacing, each consecutive run of atomic inlines (such as image and/or inline blocks) is treated as a single character
出于字母间距的目的,原子内联的每次连续运行(例如图像和/或内联块)都被视为一个字符
...has much to do with it. ...与它有很大关系。 That just indicates that such "atomic inlines" function as a unit, and an
em
is not an atomic inline by default ( see second paragraph of 9.2.2 in this spec ). 这仅表示此类“原子内联”是一个单元,默认情况下,
em
不是原子内联( 请参见本规范的9.2.2的第二段 )。 So in this example , the width
of the inline-block
element determines where the g
is placed, not the fact that the f
happens to now be after the g
, because the whole block is functioning as an atomic unit. 因此,在此示例中 ,
inline-block
元素的width
决定了g
的放置位置,而不是f
恰好位于g
之后的事实,因为整个块都充当原子单元。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.