我正在尝试创建一个数据表,但在样式方面遇到了一些问题。
1)我试图将交替行应用于未触发的TR。
有没有办法应用交替风格而不将课程传递给所有 TD
每个 TR 中都有..?
2) Colgroup正在IE8中工作,特别是对齐
(cols=A&SI资本分配,Cap Var,A&SI费用分配,Exp Var)
有没有办法解决这个问题
这里是代码:http://jsfiddle.net/yvJ75/1/
I am trying to create a data table, where I am facing few issues with styling.
1) I am trying to apply alternating row to TR which is not firing.
Is there any way to apply the alternating style without passing the class to all the TD's
with in each TR..?
2) Colgroup is working in IE8, particularly with alignment
(cols=A&SI Capital Allocation, Cap Var, A&SI Expense Allocation, Exp Var)
Is there any way to apply fix this issue
Here is the code: http://jsfiddle.net/yvJ75/1/
发布评论
评论(2)
您可以使用 CSS3 伪类 nth-child(odd) 和 nth-child(even)。
我在这里更新了代码: http://jsfiddle.net/yvJ75/12/
这些是CSS 的变化
You can use CSS3 pseudo-classes nth-child(odd) and nth-child(even).
I have updated the code here: http://jsfiddle.net/yvJ75/12/
These are the changes in the CSS
是的 - 您可以应用
之类的类,并使用
tr.even-row td
之类的 css 选择器来应用背景。这种方法适用于所有浏览器。您甚至可以使用
tr:nth-child(odd)
和tr:nth-child(even)
,但这是 css3 伪类。你的意思是它不起作用吗?列仅接受边框、背景、宽度和可见性 CSS 属性。 Td 不会继承其他属性,因为它们不是 col 元素的直接后代(可以在 此处)。最可靠的方法是在 td 上设置一个类,并根据该类设置 td 内容的样式。
Yes - you can apply the class like
<tr class="even-row">
and use a css selector liketr.even-row td
to apply background to<td>
. This approach works in all browsers. You could even usetr:nth-child(odd)
andtr:nth-child(even)
, but this are css3 pseudo classes.You mean it's not working? Columns accept only border, background, width and visibility css properties. Td's won't inherit other properties since they are not a direct descendant of the col element (a bit on understanding this can be found here). The most solid way is to set a class on td and style the td contents trought that.