Why is styling table columns not allowed?

那年仲夏 提交于 2019-11-27 22:50:14
Quentin

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.

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.

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"?

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!