独立属性(如 cellpadding)的 css 优先级
我知道通过“style”属性的内联样式优先于外部 css 文件中指定的样式。但是像“cellpadding”这样的独立属性又如何呢?示例行如下所示:
<table cellpadding="4" class="list">
I know that inline styles via the 'style' attribute take precedence over those specified in an external css file. But what about stand-alone attributes like 'cellpadding'? An example line would be like this:
<table cellpadding="4" class="list">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
6.4.4 CSS 2.1 规范中非 CSS 表示提示的优先级说:“UA 可以选择尊重 HTML 源文档中的表示属性。如果是这样,这些属性将被转换为相应的 CSS 规则,特异性等于 0,并被视为好像它们被插入到作者样式表的开头。因此,它们可能会被后续的样式表规则覆盖。”
因此,所应用的任何作者样式表中的任何相关设置都会覆盖单元格间距的效果。该属性将表的每个单元格的填充(在每个方向上)设置为指定的像素值。因此,如果您为特定单元格设置例如
padding-right: 0
,它将具有右侧填充和其他方向的 4px 填充。6.4.4 Precedence of non-CSS presentational hints in the CSS 2.1 spec says: “The UA may choose to honor presentational attributes in an HTML source document. If so, these attributes are translated to the corresponding CSS rules with specificity equal to 0, and are treated as if they were inserted at the start of the author style sheet. They may therefore be overridden by subsequent style sheet rules.”
So any relevant setting in any author style sheet being applied overrides the effect of
cellspacing
. The attribute sets the padding (in each direction) for each cell of the table to the specified value in pixels. So if you set e.g. for a particular cellpadding-right: 0
, it will have that right padding and 4px padding in other directions.“内联样式” - 应用于元素本身 - 具有最高的“特异性”,这是用于计算哪些规则覆盖其他规则(高特异性覆盖低)的点系统。
我认为
cellpadding="4"
算作内联样式,并且这是您可以在样式表中使用!important
声明覆盖它的唯一方法。以下是有关特异性的一些阅读: http://reference.sitepoint.com/css/specificity
'Inline styles' - applied to the element itself - have the highest 'specificity', which is the points system used to calculate which rules override others (high specificity overrides low).
I would imagine that
cellpadding="4"
counts as an inline style, and that the only way you could override it with an!important
declaration in your stylesheet.Here's some reading on specificity: http://reference.sitepoint.com/css/specificity