0

在 CSS 中,我有

table {
    max-width:100%;
    background-color:transparent;
    border-collapse:collapse;
    border-spacing:0
}

在 HTML 中,我有

<table class="table">
        <tr>
           <td>
               <img width="90px" src="logo.png">
           </td>

           <td>
               <div class="page-header">Header
           <td>
        </tr>
</table>

如何在不更改CSS 文件<td>中其他table的情况下更改第二个的背景颜色?<td>

请注意,我使用 Bootstrap 作为我的基础 CSS。而且在修改代码时有点复杂。

4

5 回答 5

4

将类添加到所需的<td>元素。

在那里class,指定所需的background

有关工作示例,请参见此处

于 2013-01-26T18:24:38.957 回答
4

使用 CSS 你可以像

    table tr:first-child td:nth-child(2){
         background:red;
    }
于 2013-01-26T18:18:39.333 回答
2

向要更改的 td 添加一个类(例如,使用 'headerTd'):

<table class="table">
    <tr>
    <td><img width="90px" src="logo.png"></td>

    <td class="headerTd"><div class="page-header">Header<td>
    </tr>
</table>

然后将以下规则添加到您的 css 中:

.headerTd{
    background-color:red;
}
于 2013-01-26T18:18:09.113 回答
0

You can go for styling only the 2nd simply give the style attribute.

style="color:red"
于 2013-01-26T18:12:37.387 回答
0
.secondTD {
    background:red;
}


<table class="table">
        <tr>
        <td><img width="90px" src="logo.png"></td>

        <td class="secondTD"><div class="page-header">Header<td>
        </tr>
</table>

但是如果你想不上课,那么

table:tr:td {
    background:red;
}


<table class="table">
        <tr>
        <td><img width="90px" src="logo.png"></td>

        <td><div class="page-header">Header<td>
        </tr>
</table>

如果每一行都有第一个 td:

table>tr:td {
    background:red;
}
于 2013-01-26T18:16:57.367 回答