悬停时突出显示整个表格行

Posted

技术标签:

【中文标题】悬停时突出显示整个表格行【英文标题】:Highlight entire table row on hover 【发布时间】:2018-01-07 08:52:29 【问题描述】:

我有一个表格,当它悬停在上面时,我想突出显示整行,并且整行可以作为链接点击。现在,当您在文本区域内时,它仅作为可点击链接悬停。它正确地悬停在整个宽度上,但是一旦您经过文本区域,它将无法在顶部和底部工作。请参阅我的网页 www.twoguysplayingzelda.com/athenaveta/ 以获取此示例。

.post-content table 
  border-collapse: collapse;
  border-spacing: 0;
  empty-cells: show;
  font-size: 0.9em;
  width: 100%;


.post-content th,
.post-content td 
  padding: 2%;
  margin: 0;
  overflow: visible;
  line-height: 75%;
  border-top: 2px solid #000000;
  border-bottom: 2px solid #000000;


.post-content caption 
  text-align: center;
  padding: 2%;


.post-content thead 
  vertical-align: bottom;
  white-space: nowrap;


.post-content th 
  font-weight: bold;


table tr td a 
  display: block;
  height: 100%;
  width: 100%;


td:hover 
  background: #f0f0f5;
<table>
  <tbody>
    <tr>
      <td><strong><span id="writer-pages" style="font-size: 14pt; font-family: 
    Latin, 'Architects Daughter';"><a 
    href="http://twoguysplayingzelda.com/news/check-out-this-epic-rap-battle-
    between-zelda-and-peach/">Check out this epic rap battle between Zelda and 
    Peach!</a></span></strong></td>
    </tr>
    <tr>
      <td><strong><span id="writer-pages" style="font-size: 14pt; font-family: 
    Latin, 'Architects Daughter';"><a 
    href="http://twoguysplayingzelda.com/news/the-trouble-with-triforces/">The 
    Trouble with Triforces</a></span></strong></td>
    </tr>
    <tr>
      <td><strong><span id="writer-pages" style="font-size: 14pt; font-family: 
    Latin, 'Architects Daughter';"><a 
    href="http://twoguysplayingzelda.com/news/acapella-a-tribute-to-zelda-
    themes/">Acapella: A Tribute to Zelda Themes</a></span></strong></td>
    </tr>
  </tbody>
</table>

【问题讨论】:

【参考方案1】:

像这样更新你的css文件:

.post-content table 
  border-collapse: collapse;
  border-spacing: 0;
  empty-cells: show;
  font-size: 0.9em;
  width: 100%;


.post-content th,
.post-content td 
    padding: 0px;
    margin: 0;
    overflow: visible;
    line-height: 75%;
    border-top: 2px solid #000000;
    border-bottom: 2px solid #000000;


.post-content caption 
  text-align: center;
  padding: 2%;


.post-content thead 
  vertical-align: bottom;
  white-space: nowrap;


.post-content th 
  font-weight: bold;


table tr td a 
    display: block;
    height: 100%;
    width: 100%;
    padding: 2%;


td:hover 
  background: #f0f0f5;

例子:

.post-content table 
  border-collapse: collapse;
  border-spacing: 0;
  empty-cells: show;
  font-size: 0.9em;
  width: 100%;


.post-content th,
.post-content td 
    padding: 0px;
    margin: 0;
    overflow: visible;
    line-height: 75%;
    border-top: 2px solid #000000;
    border-bottom: 2px solid #000000;


.post-content caption 
  text-align: center;
  padding: 2%;


.post-content thead 
  vertical-align: bottom;
  white-space: nowrap;


.post-content th 
  font-weight: bold;


table tr td a 
    display: block;
    height: 100%;
    width: 100%;
    padding: 2%;


td:hover 
  background: #f0f0f5;
<table>
  <tbody>
    <tr>
      <td><strong><span id="writer-pages" style="font-size: 14pt; font-family: 
    Latin, 'Architects Daughter';"><a 
    href="http://twoguysplayingzelda.com/news/check-out-this-epic-rap-battle-
    between-zelda-and-peach/">Check out this epic rap battle between Zelda and 
    Peach!</a></span></strong></td>
    </tr>
    <tr>
      <td><strong><span id="writer-pages" style="font-size: 14pt; font-family: 
    Latin, 'Architects Daughter';"><a 
    href="http://twoguysplayingzelda.com/news/the-trouble-with-triforces/">The 
    Trouble with Triforces</a></span></strong></td>
    </tr>
    <tr>
      <td><strong><span id="writer-pages" style="font-size: 14pt; font-family: 
    Latin, 'Architects Daughter';"><a 
    href="http://twoguysplayingzelda.com/news/acapella-a-tribute-to-zelda-
    themes/">Acapella: A Tribute to Zelda Themes</a></span></strong></td>
    </tr>
  </tbody>
</table>

【讨论】:

如果你给出一个更简短的例子而不是编辑 OP 的整个代码并粘贴它会很好。我确信它帮助 OP 解决了他的问题,但对于任何访问它的人来说,它不会那么有用。

以上是关于悬停时突出显示整个表格行的主要内容,如果未能解决你的问题,请参考以下文章

选择表格行并使用 Twitter Bootstrap 保持突出显示

突出显示 HTML 表格中悬停行中没有行跨度的单元格

jQuery 突出显示表格行

悬停在表格上时如何突出显示表格的行和列?

在表格中悬停单元格时突出显示特定单元格

悬停时突出显示每个表格对应元素的行和列