Bootstrap Table有什么主题或风格吗?

Is there any theme or style for Bootstrap Table?

我现在正在使用 Bootstrap 创建我正在处理的网站的前端,Bootstrap 非常好用而且功能强大。但是,HTML table 的默认样式和主题并不是那么好。 那么它有什么风格或主题吗?

我正在搜索它并找到 Bootswatch 网站。他们有非常好的 Bootstrap 免费主题,但是,这些主题不会改变 table 的风格。

Bootstrap 为带有 .table class 的表格提供基本样式。可以添加其他 classes 以获得额外的、适度的样式。

W3Schools article on Bootstrap tables

Twitter bootstrap table 可以样式化和精心设计。然而,为了让您的 table 看起来漂亮有格调,您需要创建自己的 css

你可以按照这个例子

在你的 HTML

<table class="responsive-table responsive-table-input-matrix">
  <tr>
    <th>Role</th>
    <th>Add to Page</th>
    <th>Configure</th>
    <th>View</th>
    <th>Change Permissions</th>
  </tr>

  <tr>
    <td data-th="Role">Guest</td>
    <td data-th="Add to Page"><input type="checkbox" /></td>
    <td data-th="Configure"><input type="checkbox" /></td>
    <td data-th="View"><input type="checkbox" /></td>
    <td data-th="Change Permissions"><input type="checkbox" /></td>
  </tr>
  <tr>
    <td data-th="Role">Noob</td>
    <td data-th="Add to Page"><input type="checkbox" /></td>
    <td data-th="Configure"><input type="checkbox" /></td>
    <td data-th="View"><input type="checkbox" /></td>
    <td data-th="Change Permissions"><input type="checkbox" /></td>
  </tr>
  <tr>
    <td data-th="Role">Moderator</td>
    <td data-th="Add to Page"><input type="checkbox" /></td>
    <td data-th="Configure"><input type="checkbox" /></td>
    <td data-th="View"><input type="checkbox" /></td>
    <td data-th="Change Permissions"><input type="checkbox" /></td>
  </tr>

  <tr>
    <td data-th="Role">Administrator</td>
    <td data-th="Add to Page"><input type="checkbox" /></td>
    <td data-th="Configure"><input type="checkbox" /></td>
    <td data-th="View"><input type="checkbox" /></td>
    <td data-th="Change Permissions"><input type="checkbox" /></td>
  </tr>

  <tr>
    <td data-th="Role">Owner</td>
    <td data-th="Add to Page"><input type="checkbox" /></td>
    <td data-th="Configure"><input type="checkbox" /></td>
    <td data-th="View"><input type="checkbox" /></td>
    <td data-th="Change Permissions"><input type="checkbox" /></td>
  </tr>

</table>

创建自己的CSS

@import "compass/css3";

// More practical CSS...
// using mobile first method (IE8,7 requires respond.js polyfill https://github.com/scottjehl/Respond)

$breakpoint-alpha: 480px; // adjust to your needs

.responsive-table-input-matrix {
  margin: 1em 0;
  // min-width: 300px; // adjust to your needs
  width: 100%;

  @media (min-width: $breakpoint-alpha) {
    .responsive-table-input-matrix {
      width: auto;
    }
  }

  tr {
    border-top: 1px solid #ddd;
    border-bottom: 1px solid #ddd;

    td {
      text-align: left;

      @media (min-width: $breakpoint-alpha) {
        text-align: center;
      }
    }

    & td:first-of-type {
      text-align: left;
    }
  }

  th {
    display: none; // for accessibility, use a visually hidden method here instead! Thanks, reddit!   
  }

  td {
    display: block; 

    &:first-child {
      padding-top: .5em;
    }
    &:last-child {
      padding-bottom: .5em;
    }

    &:before {
      content: attr(data-th)": "; // who knew you could do this? The internet, that's who.
      font-weight: bold;

      // optional stuff to make it look nicer
      width: 9em; // magic number :( adjust according to your own content
      display: inline-block;
      // end options

      @media (min-width: $breakpoint-alpha) {
        display: none;
      }
    }
  }

  & th:first-of-type {
    text-align: left;
  }

  th, td {
    text-align: center;

    @media (min-width: $breakpoint-alpha) {
      display: table-cell;
      padding: .25em .5em;

      &:first-child {
        padding-left: 0;
      }

      &:last-child {
        padding-right: 0;
      }
    }

  }


}


// presentational styling

@import 'http://fonts.googleapis.com/css?family=Montserrat:300,400,700';

body {
  padding: 0 2em;
  font-family: Montserrat, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  color: #444;
  background: #eee;
}

h1 {
  font-weight: normal;
  letter-spacing: -1px;
  color: #34495E;
}

.responsive-table {
  background: #34495E;
  color: #fff;
  border-radius: .4em;
  overflow: hidden;
  tr {
    border-color: lighten(#34495E, 10%);
  }
  th, td {
    margin: .5em 1em;
    @media (min-width: $breakpoint-alpha) { 
      padding: 1em !important; 
    }
  }
  th, td:before {
    color: #dd5;
  }
}

希望你能从这个编码中学到一些东西。 :)