代码之家  ›  专栏  ›  技术社区  ›  Wais Kamal

如果一行有一个具有“rowspan”属性的单元格,如何高亮显示两个表行?

  •  3
  • Wais Kamal  · 技术社区  · 8 年前

    这是桌子的样子:

    table {
      border-collapse: collapse;
    }
    <table border="1">
      <tr>
        <td rowspan="2">Text here</td>
        <td>The row 1 text goes here</td>
      </tr>
      <tr>
        <td>The row 2 text goes here</td>
      </tr>
      <tr>
        <td rowspan="2">Text here</td>
        <td>The row 1 text goes here</td>
      </tr>
      <tr>
        <td>The row 2 text goes here</td>
      </tr>
      <tr>
        <td rowspan="2">Text here</td>
        <td>The row 1 text goes here</td>
      </tr>
      <tr>
        <td>The row 2 text goes here</td>
      </tr>
    </table>

    我想实现的是,当用户将鼠标悬停在其中一行上时,相邻的另一行以及用户悬停的行都会高亮显示。我试过这个:

    table {
      border-collapse: collapse;
    }
    
    table tr:nth-child(odd):hover {
      background: #CCC;
    }
    
    table tr:nth-child(odd):hover + tr {
      background: #CCC;
    }
    
    table tr:nth-child(even):hover {
      background: #CCC;
    }
    <表格边框=“1”>
    <td行span=“2”>此处显示文本</td>
    <td>第1行文本位于此处</td>
    </tr>
    <tr>
    <td>第2行文本位于此处</td>
    <tr>
    <td行span=“2”>此处显示文本</td>
    <td>第1行文本位于此处</td>
    <tr>
    <td>第2行文本位于此处</td>
    </tr>
    <tr>
    <tr>
    <td>第2行文本位于此处</td>
    </tr>
    </表>

    我想的是 <rowgroup> .

    1 回复  |  直到 8 年前
        1
  •  4
  •   Ori Drori    8 年前

    这个 tbody multiple times :

    table {
      border-collapse: collapse;
    }
    
    tbody:hover {
      background: #CCC;
    }
    <table border="1">
      <tbody>
        <tr>
          <td rowspan="2">Text here</td>
          <td>The row 1 text goes here</td>
        </tr>
        <tr>
          <td>The row 2 text goes here</td>
        </tr>
      </tbody>
      <tbody>
        <tr>
          <td rowspan="2">Text here</td>
          <td>The row 1 text goes here</td>
        </tr>
        <tr>
          <td>The row 2 text goes here</td>
        </tr>
      </tbody>
      <tbody>
        <tr>
          <td rowspan="2">Text here</td>
          <td>The row 1 text goes here</td>
        </tr>
        <tr>
          <td>The row 2 text goes here</td>
        </tr>
      </tbody>
    </table>