javascript - Bootstrap 表悬停不起作用

标签 javascript jquery html css twitter-bootstrap

我正在使用 bootstrap 3.3.4,但遇到了问题。 如果我检查我正在加载的 bootstrap.css 文件,有一个 table-hover 类,但我不能使用它,它只是不起作用,正如我所看到的,例如 table-bordered 是有效的。我检查过 bootstrap.js 也已加载。其他人有同样的问题吗?我试图搜索它很长时间。 提前致谢

最佳答案

来自docs on table hover , 请确保将 .table-hover 类添加到您的表格元素中。

此外,正如 Daniel 指出的那样,bootstrap 会寻找一个 tbody 来对您的行进行分组,因为它不想在标题区域应用悬停样式。

此外,对于某些屏幕,默认的悬停颜色可能会显得很暗,因此您可以尝试使用以下代码将其调暗:

.table-hover > tbody > tr:hover {
  background-color: #D2D2D2;
}

这是 Stack Snippets 中的一个工作演示

<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" rel="stylesheet"/>


<table class="table table-hover">
  <thead>
    <tr>
      <th>#</th>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Username</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
      <th scope="row">3</th>
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>

关于javascript - Bootstrap 表悬停不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30411337/

相关文章:

html - 如何正确使用:not selector to solve . b而不是.a .b?

javascript - chrome.storage.sync.set 不保存值

javascript - 简单加法暴露 Javascript 引擎浮点错误

javascript - jQuery 自动完成插件在 ajax 加载的内容中不起作用

javascript - 选取框不显示所有文本 - 在不同点切断

html - 如何将此 HTML 表格布局解决方案转换为 float div 解决方案?

javascript - jQuery 利息计算器 - 计算每月支付的信用额度

javascript - 在 Node.js + MongoDB 中使用 REST API 插入和查询 JSON 数据

javascript - Froala WYISWYG 编辑器不显示工具栏

javascript - 响应式三列重新堆叠