更改HTML表中特定列的背景颜色 [英] Change Background color for a specific column in a HTML table
问题描述
我想更改HTML表中specif列的背景颜色。是否可以使用属性来做到这一点。我找到了行的方法。
I would like to change the background color of a specif column in a HTML table. Is it possible to use a property to do it. I found the way to do it with rows.
tr.even {
background-color: white;
}
推荐答案
列的背景,而不是行,你可以尝试这样的东西(下面)。您需要更改选择器以匹配您的HTML。
If you are looking to style the background of a column, and not a row, you can try something like this (below). You'll need to change the selectors to match your HTML.
td:first-child {background-color:#ccc; }
下面是一个小提示的链接,以及通过JS添加类的方法。有很多方法,但是由于你是处理列,记住CSS被应用到在你想要风格的每一行中相同的 td
。
Below is a link to a fiddle, along with a way to add classes via JS. There are many ways, but since you are dealing with columns, remember that the CSS is being applied to the same td
in each row you want to style.
JSFiddle
这篇关于更改HTML表中特定列的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!