【问题标题】:Bootstrap danger class not working for a table rowBootstrap 危险等级不适用于表格行
【发布时间】:2014-07-18 07:01:28
【问题描述】:

我的 Rails 应用中有下表:

<table class='table table-bordered table-hover table-striped'>
    <thead>
      <tr>
        <th>ID</th>
        <th>Status</th>
      </tr>
    </thead>

    <tbody>
      <tr class='danger'>
        <td><%= order.id %></td>
        <td><%= order.status.name %></td>
      </tr>
    </tbody>
  </table>

“危险”类的行不会改变颜色。但是,如果我使用“成功”类,它会正确更改。

我正在使用 twitter-bootstrap-rails gem。

【问题讨论】:

  • 你能发布一个关于这个错误的小提琴吗?我们没有足够的信息来正确回答

标签: css ruby-on-rails twitter-bootstrap


【解决方案1】:

通过https://getbootstrap.com/docs/4.3/content/tables/#contextual-classes这里他们指定了所有行和单元格类,你应该修改你的

<table class='table table-bordered table-hover table-striped'>
<thead>
  <tr>
    <th>ID</th>
    <th>Status</th>
  </tr>
</thead>

<tbody>
  <tr class='table-danger'>//Modified line
    <td><%= order.id %></td>
    <td><%= order.status.name %></td>
  </tr>
</tbody>

【讨论】:

    【解决方案2】:

    也许您正在使用旧版本的 Bootstrap gem,顺便说一下默认 gem 尚未更新到 Bootstrap 的第 3 版,请尝试使用此资源

    https://github.com/jasontorres/bootstrap-on-rails

    正如@Kirti 所说,Bootstrap 2 版本的正确类必须是 .error 而不是 .danger 观看官方文档:

    http://getbootstrap.com/2.3.2/base-css.html#tables

    【讨论】:

      【解决方案3】:

      twitter-bootstrap gem 当前正在使用bootstrap v 2.3.2

      根据Bootstrap version 2.3.2 Documentation For Tables,以下是可用的行类

      Optional row classes
      
      Use contextual classes to color table rows.
      
      .success    Indicates a successful or positive action.
      .error      Indicates a dangerous or potentially negative action.
      .warning    Indicates a warning that might need attention.
      .info       Used as an alternative to the default styles.
      

      这就是为什么 .success 有效但 .danger 无效。

      我想你正在寻找.error 类。

      【讨论】:

        【解决方案4】:

        这似乎是一个已知的表格错误。

        看起来这是 v3.0.3 中的一个已知错误,将在 v3.1.0 中修复

        参考this bug error page 和这个stack question

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-12-01
          • 2013-09-29
          • 2010-12-10
          • 2018-06-28
          • 1970-01-01
          • 2013-03-21
          • 2018-09-04
          相关资源
          最近更新 更多