【问题标题】:Changing hover color of a responsive table更改响应式表格的悬停颜色
【发布时间】:2018-01-25 06:28:14
【问题描述】:

我尝试了一个简单的技巧来改变响应式表格的悬停颜色,但失败了。

我尝试链接 CSS 但失败了。

我是否需要添加更多的 CSS 标记来实现这一点。

能否请您帮助我了解我的方法有什么问题。

这是我的代码:

    <!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script>
.table-hover thead tr:hover th, .table-hover tbody tr:hover td {
    background-color: #FF0000;
}
  </script>
</head>
<body>

<div class="container">
  <h2>Table</h2>
  <p>The .table-hover class enables a hover state on table rows within a tbody:</p>

<table class="table table-hover">
    <thead>
        <tr>
            <th>Firstname</th>
            <th>Lastname</th>
            <th>Email</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>John</td>
            <td>Doe</td>
            <td>john@example.com</td>
        </tr>
        <tr>
            <td>Mary</td>
            <td>Moe</td>
            <td>mary@example.com</td>
        </tr>
        <tr>
            <td>July</td>
            <td>Dooley</td>
            <td>july@example.com</td>
        </tr>
    </tbody>

  </table>
</div>

</body>
</html>

【问题讨论】:

  • 对我来说效果很好
  • 谢谢杰森。您能否确认您是否能够在悬停时看到红色或灰色。实际上我想要悬停时的红色,但我可以看到灰色

标签: css colors html-table hover responsive


【解决方案1】:
`<style>
 .table-hover thead tr:hover th, .table-hover tbody tr:hover td {
background-color: #FF0000;
 }
 </style>`

这段代码甚至在表头上突出显示,这个代码只在表格主体上突出显示

`<style>
 .table-hover tbody tr:hover td {
  background-color: #FF0000;
 }
 </style>`

【讨论】:

    【解决方案2】:

    您必须在 CSS 上放置样式而不是脚本

    在这里制作:

    <style>
    .table-hover thead tr:hover th, .table-hover tbody tr:hover td {
        background-color: #FF0000;
    }
    </style>
    

    【讨论】:

    • 是的,这是一个愚蠢的错误,将所需的代码放在脚本中,而不是对 css 有效的样式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-16
    • 2017-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多