CSS pseudo-class fallback?

戏子无情 提交于 2020-03-22 08:07:05

问题


I'd like to use the tr:nth-child(even/odd) pseudo class for a table, but I want to support the IE 2 population as well. So, is there any purely css way to add a border to tr if nth-child isn't supported?


回答1:


You can try Selectivizr, I think that's the easiest solution.

EDIT:

You could also use jquery to add classes for you:

$(function() {
    $("tr:odd").addClass("odd");
    $("tr:even").addClass("even");
});

EDIT2:

Also, if you're using Modernizr, you could try this.

EDIT3 :)

tr { border-bottom: 1px solid #ccc; }

tr:nth-child(odd),
tr:nth-child(even) { border: none; }

tr:nth-child(odd) { background: #eee; }

tr:nth-child(even) { background: #ddd; }



回答2:


You could add + between your classes/elements to do like in this example below, every 5 <tr> remove the margin-right

tr{margin-right:10px;}
tr + tr + tr + tr + tr{margin-right:0;}

A great replacement for NTH pseudo-classes without any javascript and IE7+ compatible ;)



来源:https://stackoverflow.com/questions/15323591/css-pseudo-class-fallback

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