表行悬停-排除特定单元格



我制作了一个价格表,当鼠标悬停时将改变行背景。由于我使用它的方式,我遇到了两个问题

  1. 有一个3行跨度,我用来保持购买按钮,因为我希望它垂直对齐在中心与列的左边。我必须使用!important来保持背景在滚动时为白色。固定的。

  2. 当您滚动购买按钮单元格时,它突出显示第一行。这是我不想要的。我试过各种各样的东西,重新安排的东西,也不能拿出任何解决方案,不删除3行跨度。

jsfiddle

<table>
<tr>
    <th colspan="3">title text</th>
</tr>
<tr>
    <td>amount</td>
    <td class="pricing">price</td>
    <td class="purchase" rowspan="3">purchase button</td>
</tr>
<tr>
    <td>amount</td>
    <td class="pricing">price</td>
</tr>
<tr>
    <td>amount</td>
    <td class="pricing">price</td>
</tr>
</table>

table{
margin:.5em 0 1em 0;
width:100%;
font-size:15px;
}
table th{
padding:0px 0 10px 5px;
}
table td{
padding:2px 5px;
}
table td.purchase{
text-align:right;
width:150px;
vertical-align:middle;
background:#ffffff !important;
}
table td.pricing{
width:130px;
border-left:5px #ffffff solid;
}
table td.details {
padding:0 35px 0 15px;
}
table tr:hover td
{
background-color: #ebf1f6;
}

我有一个类似的需求:在表格的行上应用背景色,当我用鼠标指针悬停在行上时,除了'selected'行,它已经用不同的背景色突出显示。

使用'pointer-events: none;'达到了我想要的效果:JsFiddle

table#CustOrders tbody tr:hover td {
  background-color: LemonChiffon;
}
table#CustOrders tbody tr#selected {
  background-color: Yellow;
  pointer-events: none;
}

我想到的第一件事是使用"pointer-events" css属性。但我不确定它在这里是否有用。检查此链接(有一个jsFiddle示例可用)

也考虑使用一些javascript代码来设置你需要的逻辑。我明白你想只用css,但js的修复可以相当小,明显在这里-所以为什么不呢?

您可以查看答案

<table width="100%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td colspan="2" scope="row">title text </td>
  </tr>
  <tr>
    <td width="75%" scope="row">
        <table width="100%" border="0" cellspacing="2" cellpadding="2" class="amount_table">
          <tr>
            <td>amount</td>
            <td>price</td>
          </tr>
          <tr>
            <td>amount</td>
            <td>price</td>
          </tr>
          <tr>
            <td>amount</td>
            <td>price</td>
          </tr>
        </table>    
    </td>
    <td width="25%">Purchace</td>
  </tr>
</table>
CSS

.amount_table tr:hover{
  background:gray
}

最新更新