简体   繁体   English

如何用CSS选择除IE7 / 8的最后一个单元格以外的所有单元格?

[英]how to CSS select all th cells, except the last one on IE7/8?

I'm trying to fit some CSS to also work on IE7 and IE8 and I'm stuck with the :not() selector. 我试图适应一些CSS,使其也可以在IE7和IE8上使用,但我坚持使用:not()选择器。

I need to select all table header cells except the last one. 我需要选择除最后一个单元格以外的所有表头单元格。 I'm currently using this: 我目前正在使用此:

 th:not(:last-child)

which fails on IE7+8. 在IE7 + 8上失败。

Are there any CSS only workarounds? 是否只有CSS解决方法?

Thanks for some hints! 感谢您的提示!

The way you ask it: 您的询问方式:

all table header cells except the last one 除最后一个表头外的所有表头单元格

could refer to: 可以参考:

  • the last th of the table, wherever it could be found, 最后th表,只要可以发现,
  • the last element of a row (presumably the last one of thead>tr - and there could be more than one tr there), 行的最后一个元素(大概是thead>tr的最后一个-那里可能有多个tr ),
  • the last th in each row. 最后th每个一行。

None of these cases can be solved by CSS understood by IE7/8 (resp. no solution in CSS at all, th:last-child and th:last-of-type ) 这些情况都无法通过IE7 / 8理解的CSS来解决(在CSS中根本没有解决方案, th:last-childth:last-of-type

EDIT: in one case, there could be a solution. 编辑:在一种情况下,可能有一个解决方案。 If you exactly know how many th elements there are in each row then you can select say the fourth one with th ~ th ~ th ~ th . 如果您确切知道每一行中有多少th元素,则可以选择第四th元素,并带有th ~ th ~ th ~ th
See http://reference.sitepoint.com/css/generalsiblingselector for IE7/8 bugs (no comment allowed). 有关IE7 / 8错误,请参见http://reference.sitepoint.com/css/generalsiblingselector (不允许发表评论)。
It's up to you to modify this selector if there are only th in a row (the + selector would be OK too) or if there are @colspan or @rowspan attributes (number of elements in a row != number of columns). 如果一行中只有th+选择器也可以),或者具有@colspan@rowspan属性(一行中的元素数!=列数), @rowspan您来修改此选择器。

I solved it only by adding extra class for last elements in code generator. 我仅通过为代码生成器中的最后一个元素添加额外的类来解决它。 No tool for IE8,7 and older. IE8,7及更早版本没有工具。

You can't do it with pure css . 您不能使用纯css做到这一点。 You can give class to your last th in your HTML or you can use selectivizr JavaScript for this. 你可以给类要贵上th在你的HTML也可以使用selectivizr JavaScript来此。 Selectivizr support all css3 & css2 selectors for IE older version Selectivizr支持IE旧版本的所有CSS3和CSS2选择器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM