为什么不允许设置表格列的样式?

发布于 2024-07-27 00:23:04 字数 204 浏览 10 评论 0原文

W3 指定表格列只允许使用四个 CSS 规则(其中 元素) - 边框、背景、宽度和可见性。

有谁知道这个决定背后的原因? 如果可以有边框和背景,为什么不能有字体和颜色呢?

W3 specifies that only four CSS rules are allowed for table columns (with the <col> element) - border, background, width and visibility.

Does anyone know the reasons behind this decision? If you can have borders and backgrounds, why not fonts and colours?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

莫相离 2024-08-03 00:23:04

Ian Hixie 在此详细解释:为什么只有四个属性适用于表列的奥秘。 相关报价:

文本的颜色取决于其元素的“颜色”属性。 除非指定,“color”属性(基本上)默认为“inherit”,这意味着“采用父元素的值”。

因此,对于单元格中的某些文本,颜色由单元格的“颜色”属性决定,该属性取自行,该行取自表格,该属性取自表格的父级,依此类推.

专栏怎么样? 嗯,该列不是单元格的祖先之一,因此它永远不会被查看! 这就是问题所在。

Ian Hixie explains in detail here: The mystery of why only four properties apply to table columns. Relevant quote:

The colour of text is dependent on the 'color' property of its element. Unless specified, the 'color' property (basically) defaults to 'inherit', which means "take the value of the parent element".

So for some text in a cell, the colour is determined by the 'color' property of the cell, which is taken from the row, which is taken from the table, which is taken from the table's parent, and so on.

What about the column? Well, the column isn't one of the cell's ancestors, so it never gets a look-in! And therein lies the problem.

樱花落人离去 2024-08-03 00:23:04

只是基于我有限的理解,在黑暗中进行了疯狂的尝试:

我认为通过与列相关的元素进行样式设置是受到限制的,因为尽管 代表列单元格,它实际上并不包含它们(它们实际上包含在 中)。 随之而来的是优先级、特异性和级联问题(因为级联只能在包含的/容器元素之间完成) - 当 < 的样式规则发生冲突时/code> (这将是多重继承层次结构中的同一级别)发生 - 单元格实际应该使用哪个?

至于为什么允许特定的少数样式属性:不知道。

Just a wild stab in the dark based upon my limited understanding:

I think styling via column related elements is restricted because although <col> and <colgroup> represent columns of cells, it does not actually contain them (they're actually contained by the <tr>s). With this comes issues of precedence and specificity and cascading (since cascading can only be done between contained/ container elements) - when conflicting style rules from the <tr> and <col> (which would be the same level in a multiple inheritance hierarchy) occur - which should the cell actually use?

As to why that particular handful of style attributes is permitted though: no idea.

您的好友蓝忘机已上羡 2024-08-03 00:23:04

一个词:暧昧。 单元格必须是行的子单元格; 否则它就不是一张桌子了。 但没有可以下降的柱子。 使用 colspan 意味着一个单元格可以位于两列中。 与其试图想出一些令人困惑的解决办法,为什么不让开发人员在每个第 n 个单元格上放置一个 class 呢?

如果您仔细查看链接到的规范,您将看到解决歧义的尝试。 width 属性指定最小值; 背景 位于行和单元格之后; border 引用了“冲突解决算法”。 甚至存在边界算法的唯一原因是因为可以合理地理解谁应该“获胜”(有关详细信息,请参阅算法)。 但是您能想象尝试找出哪种颜色字体应该“获胜”吗?

One word: ambiguity. The cells have to be children of rows; it wouldn't be a table otherwise. But there is no column to descend from. Using colspan means that one cell could be in two columns. Rather than trying to come up with some confusing way out, why not just let the developer place a class on every nth cell?

If you look closely at the spec to which you link, you will see attempts at ambiguity resolution. The width property specifies a minimum; the background takes a backseat to the row and cell; and border references a "conflict resolution algorithm". The only reason there is even an algorithm for border is because it is reasonably understood who should "win" (see the algorithm for details). But could you imagine trying to figure out which color or font should "win"?

许久 2024-08-03 00:23:04

可能是因为表中的每一行不一定必须显示列的单元格(例如,由于 colspan)。 该单元格应该从哪一列继承其样式? 只是一个猜测。

Possibly because each row in the table does not necessarily have to display a cell for your column (e.g. because of a colspan). Which column should that cell inherit it's style from? Just a guess.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文