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

时间:2015-06-29 03:50:44

标签: css twitter-bootstrap-3 html-table

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

我正在搜索它并找到Bootswatch网站。他们为Bootstrap提供了非常好的免费主题,但是,这些主题并没有改变表格的风格。

2 个答案:

答案 0 :(得分:0)

Bootstrap为具有.table类的表提供基本样式。还可以添加其他类来进行额外的,适度的样式。

W3Schools article on Bootstrap tables

答案 1 :(得分:0)

Twitter引导程序表可以设计样式并且设计得很好。然而,为了让你的桌子看起来漂亮和风格,你需要创建自己的CSS

您可以按照此示例enter image description here

进行操作

在您的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;
  }
}

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