Override table style on nested inner table

白昼怎懂夜的黑 提交于 2019-12-13 17:22:29

问题


Please view my js fiddle:

http://jsfiddle.net/WillingLearner/gzYPU/7/

As you can clearly see when you run the fiddle, the inner table with the border is not displaying its own styles. Its inheriting the style from the parent.

Please help me display the inner table with its own styles only, while still remaining nested in the parent table row.


回答1:


There are various ways to fix your problem. You have two styles on tr:

#MainTable_Forums tr:nth-child(even)
#MainTable_Forums tr:nth-child(odd)

These are being used for the inner tr as ID rules bind tighter than class rules.

You can also insert a <tbody> in the the HTML and then use these for the striping:

#MainTable_Forums > tbody > tr:nth-child(even)
#MainTable_Forums > tbody > tr:nth-child(odd)

Some browsers will insert the <tbody> for you so you'll need to have it in the selectors and the HTML to, hopefully, cover all the cases. Example: http://jsfiddle.net/ambiguous/b6zEy/

Depending on your specific needs you could replace your inner tr rule with this:

.ThreadInfo_Container td

to apply the style directly to the td. The effect isn't quite the same but it might, depending on your specific situation, work better; some browsers make a mess of borders on tr elements, some are fine with it. Example: http://jsfiddle.net/ambiguous/a4LEg/




回答2:


The selector for the inner table is less specific than the one(s) for the outer table, hence the styles of the outer table have precedence. You can make the selector for the inner table more specific like so:

#MainTable_Forums .ThreadInfo_Container tr { ... }


来源:https://stackoverflow.com/questions/4779192/override-table-style-on-nested-inner-table

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