使用rowspan列在行中插入背景图像

时间:2017-05-24 03:25:35

标签: html css

我有一张桌子

<table>
    <tr>
        <td rowspan="2"></td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
    </tr>
<table>

和CSS

table tr:nth-child(2n+1) { background:url("path"); }

但结果就在这里

enter image description here

即背景图像不覆盖行但第二行出现! 如何将背景图像应用于行显示的行

1 个答案:

答案 0 :(得分:1)

为什么不给一个你想要影响的单元格?

这里我给rowspan个单元格一个background类,你可以看到背景应用于这两行:

td.background {
  background: url("http://placehold.it/100");
}

td {
  background: red;
  width: 200px;
  height: 30px;
}
<table>
  <tr>
    <td class="background" rowspan="2"></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
  </tr>
  <table>

希望这有帮助! :)