【发布时间】:2019-08-27 21:07:01
【问题描述】:
我在玩与a:link around div - styling inside div 相关的代码时注意到了这一点(奇怪?)
鉴于此 HTML:
<a id="foo" href="foobar">
<div id="bar">
<h2 id="baz">Foo</h2>
</div>
</a>
还有这个 CSS(添加背景颜色以显示结构):
a {
display: block;
padding: 20px;
background-color: rgb(240,240,240);
}
#bar {
width: 200px;
height: 100px;
background-color: rgb(220,220,220);
}
#baz {
padding: 20px;
text-decoration: none;
}
Chrome 将匹配的 CSS 规则显示为包含 text-decoration: none;,但文本确实带有下划线:
(来源:pangram.net)
同样,使用 Firebug,Firefox 会为 textDecoration 计算样式返回 null:
(来源:pangram.net)
MDN says that text-decoration applies to all elements.
我意识到将text-decoration 属性应用于a 链接有一个简单的解决方法,但这不是我所期望的行为。谁能解释这个(明显的)差异?
编辑:我相信答案就在这里:Line Decoration: Underline, Overline, and Strike-Through
当指定或传播到一个块容器时 内联格式化上下文,装饰被传播到 包装所有流入内联级子级的匿名内联框 块容器。
但我仍然不完全明白发生了什么。
【问题讨论】:
标签: css