繁体   English   中英

如何更改html中单个列的背景颜色?

[英]How can I change the background color for a single column in html?

如何更改html中单个列的背景颜色? 我有几个html页面链接到具有12列网格的css文件,并且我将某些html页面中一列的背景更改为与常规背景色(白色)不同的颜色,但其他列则没有。 另外,我想更改此列的文本颜色。 我怎样才能做到这一点?

与HTML table元素相关,可以实现,如以下示例所示:

<table>
<tr>
<td></td>
<td style="background-color:#909090;"></td>
<td></td>
</tr>
</table>

或者,以更复杂的方式使用CSS3样式,例如:

table td:nth-child(2)
{
  background-color:#909090;
}

希望这会有所帮助。

如果您不是使用<table>而是使用<div>标签来构建布局,则可以这样实现:

<div class="container">
    <div>
        First column
    </div>
    <div style="background-color: red">
        Second column
    </div>
    ...
</div>

或者,在CSS中:

.container div:nth-child(2) {
    background-color: red;
}

 <table> <colgroup> <col span="2" style="background-color:red"> <col style="background-color:yellow"> </colgroup> <tr> <th>ISBN</th> <th>Title</th> <th>Price</th> </tr> <tr> <td>3476896</td> <td>My first HTML</td> <td>$53</td> </tr> <tr> <td>5869207</td> <td>My first CSS</td> <td>$49</td> </tr> </table> 

暂无
暂无

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

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