html - 突出显示悬停行和下一行

标签 html css

我正在使用此 CSS 突出显示悬停的行。

.table tbody tr:hover td, .table tbody tr:hover th {
    background-color: #eeeeea;
} 

我的问题是我正在使用 rowspan=2,所以我需要突出显示行跨度中的行。它的 css 是什么。

HTML

<table class="table">
<thead>
  <tr>
    <th></th>
    <th width="10%" >Req ID</th>
    <th width="10%">Date</th>
    <th width="5%">Qty</th>
    <th colspan="3" width="45%">Plant Info</th> 
    <th width="10%">Picture</th>
    <th width="10%">Pic type</th>
    <th width="30%" >Action</th>

  </tr>
</thead>
<tbody>


 <tr>
    <td rowspan="2"></td>
    <td rowspan="2"></td>
    <td rowspan="2"></td>
    <td rowspan="2"></td>
    <td></td>
    <td></td>
    <td></td>
    <td rowspan="2"></td>
    <td rowspan="2"></td>   
    <td rowspan="2"></td>
  </tr>
  <tr>
    <td colspan="3"></td>
  </tr>
   <tr>
        <td rowspan="2"></td>
        <td rowspan="2"></td>
        <td rowspan="2"></td>
        <td rowspan="2"></td>
        <td></td>
        <td></td>
        <td></td>
        <td rowspan="2"></td>
        <td rowspan="2"></td>   
        <td rowspan="2"></td>
      </tr>
      <tr>
        <td colspan="3"></td>
      </tr>


</tbody>

问题的屏幕截图。此行有行跨度,而我将其悬停时仅突出显示第一行。 enter image description here

最佳答案

除非我误解了你的问题

.table tbody td:hover, .table tbody th:hover {
background-color: #eeeeea;
}

.table tbody tr td:hover, .table tbody tr th:hover {
background-color: #eeeeea;
}

由于您使用的是“.table”,因此您的表需要有一个“名为表的类” .给它上课后,它应该可以工作。

更新

可能还有一些其他的方法,但是我想你可以像下面那样使用纯 HTML 和 CSS。

trtbody 组合在一起,然后将鼠标悬停在 tbody 上。

HTML

<table class="table" border=1>
    <thead>
        <tr>
            <th></th>
            <th width="10%">Req ID</th>
            <th width="10%">Date</th>
            <th width="5%">Qty</th>
            <th colspan="3" width="45%">Plant Info</th>
            <th width="10%">Picture</th>
            <th width="10%">Pic type</th>
            <th width="30%">Action</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td rowspan="2">asd</td>
            <td rowspan="2">d</td>
            <td rowspan="2">s</td>
            <td rowspan="2">d</td>
            <td>asd</td>
            <td>asd</td>
            <td>asd</td>
            <td rowspan="2">asd</td>
            <td rowspan="2">ds</td>
            <td rowspan="2">asd</td>
        </tr>
        <tr>
            <td colspan="3"></td>
        </tr>
    </tbody>
    <tbody>
        <tr>
            <td rowspan="2"></td>
            <td rowspan="2"></td>
            <td rowspan="2"></td>
            <td rowspan="2"></td>
            <td></td>
            <td></td>
            <td></td>
            <td rowspan="2"></td>
            <td rowspan="2"></td>
            <td rowspan="2"></td>
        </tr>
        <tr>
            <td colspan="3"></td>
        </tr>
    </tbody>

CSS

.table tbody:hover {
    background-color:yellow;
}

关于html - 突出显示悬停行和下一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29024690/

相关文章:

javascript - 检测按钮点击 z-index -1

html - 单行动态列数的CSS解决方案

css - 如何将CSS样式添加到kineticjs

jquery - 从 bootstrap 下拉菜单中选择选项,该选项显示更多/隐藏的内容

html - 数据表中的页码列表对齐方式

javascript - 如何重新初始化 Owl Carousel 2.0?

python - HTML 电子邮件显示为纯文本?

javascript - bootstrap-modal.js 在 Bootstrap 3 中损坏

javascript - onChange 按钮标签不保持其样式

jquery - CSS:重新排列 div 元素