twitter-bootstrap Twitter Bootstrap 在使用 <th> 而不是 <td> 时不会改变颜色表标题行的颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14476275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 16:10:43  来源:igfitidea点击:

Twitter Bootstrap is not changing color table header row's color while using <th> instead of <td>

twitter-bootstrapruby-on-rails-3.2

提问by Siddharth

In my rails 3.2 application I have to display a table. So I used the twitter bootstrap's class "table table-bordered"to format it. And then to change it's rows color I also used class "info" and "success" described here.

在我的 rails 3.2 应用程序中,我必须显示一个表格。所以我使用了 twitter bootstrap 的类“table table-bordered”来格式化它。然后要更改它的行颜色,我还使用了此处描述的“信息”和“成功”类。

The table code in my page is as follows:-

我页面中的表格代码如下:-

<table class="table table-bordered">
  <tr class="info">
    <th>Your Links</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<% @links.each do |link| %>
  <tr class="success">
    <td><%= link_to linkbunch_url(link.link), linkbunch_url(link.link) %></td>
    <td><%= link_to 'Show', linkbunch_url(link.link) %></td>
    <td><%= link_to 'Edit', edit_url(link.link) %></td>
    <td><%= link_to 'Destroy', destroy_url(link.link), method: :delete, data: { confirm: 'Are you sure ?' } %></td>
  </tr>
<% end %>
</table>

Guess what it's changing all rows colors except the first row that is the the head row of table. But when changed the ""to ""then it's working fine. But because it's just a simple row not a table header row so it's fonts are not bold type.

猜猜它正在改变除表头行的第一行之外的所有行颜色。但是,当改变了“”“”那么它的正常工作。但是因为它只是一个简单的行而不是表格标题行,所以它的字体不是粗体。

So How to change the header row's color without using the instead of ??

那么如何在不使用的情况下更改标题行的颜色 代替 ??

Thanks...

谢谢...

采纳答案by hajpoj

There is no css in bootstrap for adding .infoor .successto the table header. You have to make the rule yourself.

bootstrap 中没有用于添加.info或添加.success到表头的css 。你必须自己制定规则。

.table tbody tr.info th {
    background-color: #d9edf7;
}

jsfiddle

提琴手

回答by gavit

<table class="table table-bordered">
  <thead>
    <tr class="info">
      <th>Your Links</th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
<% @links.each do |link| %>
  <tr class="success">
    <td><%= link_to linkbunch_url(link.link), linkbunch_url(link.link) %></td>
    <td><%= link_to 'Show', linkbunch_url(link.link) %></td>
    <td><%= link_to 'Edit', edit_url(link.link) %></td>
    <td><%= link_to 'Destroy', destroy_url(link.link), method: :delete, data: { confirm: 'Are you sure ?' } %></td>
  </tr>
<% end %>
  </tbody>
</table>