所以我读过the previous disccussion关于这个主题,我知道文本装饰是传播的而不是继承的,但是 spec没有说为什么。我试图更好地理解为什么会出现这种情况,以及为什么定位很重要。这种行为有什么好处?我对此感到惊讶,因为它不直观。 CSS 中还有其他我应该注意的示例吗?
最佳答案
考虑这个标记,它早于 CSS。
<strike>The <a href="http://example.com/">example</a> is here.</strike>
<strike>
默认为 text-decoration:line-through
,而 <a href="...">
默认为 text-decoration:underline
。在 CSS 出现之前,“example”这个词会带有下划线和删除线,因此 CSS 需要能够实现相同的效果。为此,规范编写者选择让 text-decoration
累积而不是继承。
另一种方法是为每个 text-decoration
值赋予其自己的属性。 CSS 之父 Håkon Wium Lie 在 message to the www-style mailing list in May 1997 中解决了这个问题:
There is no easy way to turn off blinking without also throwing out other values set on the text-decoration property. This was sacrificed for the sake of brevity -- the alternatives would be to have separate binary properties for all values on 'text-decoration'.
当时预计 text-decoration
将扩展到比它最终拥有的四个装饰更多的内容 - several had already been dropped from the draft spec 。
所以你知道了,CSS 的设计者当时并不希望属性激增。
很难证明这样的负面影响,但我不知道有任何其他属性以这种方式传播。
关于html - text-decoration 缺乏继承性的原因是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69713054/