【问题标题】:Getting a table cell to become a different color on mouseover让表格单元格在鼠标悬停时变成不同的颜色
【发布时间】:2017-06-04 01:52:15
【问题描述】:

目前,当我创建一个表格并将鼠标悬停在一个单元格上时,整行都会突出显示。我正在努力使它只是直接的单元格。以下是与我的样式表中的表格相关的所有 CSS 代码:

table{margin:.5em 0 1em;}
table td,table th{text-align:center;border-right:1px solid #fff;padding:.4em .8em;}
table th{background-color:#5e5e5e;color:#fff;text-transform:uppercase;font-weight:bold;border-  bottom:1px solid #e8e1c8;}
table td{background-color:#eee;}
table th a{color:#d6f325;}
table th a:hover{color:#fff;}
table tr.even td{background-color:#ddd;}
table tr:hover td{background-color:#fff;}

table.nostyle td,table.nostyle th,table.nostyle tr.even td,table.nostyle tr:hover td{border:0;background:none;background-color:transparent;}

我知道这可能是一个简单的修复,但我找不到让它工作的地方。我尝试的一切只是完全消除鼠标悬停效果,而不是按照我想要的方式。

【问题讨论】:

    标签: css hover css-tables


    【解决方案1】:

    改变

    table tr:hover td{background-color:#fff;}
    

    table td:hover <strike>td</strike>{background-color:#fff;}
    

    这应该突出显示单元格而不是整行。

    更新 tr:hover 被提及两次。它也应该是td:hover,而不是td:hover td。这应该有效:

    table{margin:.5em 0 1em;}
    table td,table th{text-align:center;border-right:1px solid #fff;padding:.4em .8em;}
    table th{background-color:#5e5e5e;color:#fff;text-transform:uppercase;font-weight:bold;border-  bottom:1px solid #e8e1c8;}
    table td{background-color:#eee;}
    table th a{color:#d6f325;}
    table th a:hover{color:#fff;}
    table tr.even td{background-color:#ddd;}
    table td:hover {background-color:#fff;}
    
    table.nostyle td,table.nostyle th,table.nostyle tr.even td,table.nostyle td{border:0;background:none;background-color:transparent;}
    

    【讨论】:

    • :hover 可能对除锚标记以外的任何东西都不起作用,除非您有严格的浏览器控制。
    • 那行不行,我已经尝试了该行中 td 和 tr 的所有组合,但它从来没有用过。
    猜你喜欢
    • 2014-03-27
    • 2012-07-02
    • 2015-09-29
    • 2017-01-12
    • 2017-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-28
    相关资源
    最近更新 更多