【问题标题】:Applying styles to tables with Twitter Bootstrap使用 Twitter Bootstrap 将样式应用于表格
【发布时间】:2012-03-07 04:00:48
【问题描述】:

有谁知道是否可以使用 Twitter Bootstrap 在表格上应用样式?我可以在一些较早的教程中看到一些表格示例,但在 Bootstrap 站点本身上看不到。

我尝试设置它,但我页面中的表格几乎没有应用任何样式。

<table>
    <thead>
        <tr>
            <th>#</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Language</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Some</td>
            <td>One</td>
            <td>English</td>
        </tr>
        <tr>
            <td>2</td>
            <td>Joe</td>
            <td>Sixpack</td>
            <td>English</td>
        </tr>
    </tbody>
</table>

我需要申请哪些课程?

【问题讨论】:

    标签: twitter-bootstrap


    【解决方案1】:

    Bootstrap 提供各种表格样式。查看Base CSS - Tables 获取文档和示例。

    以下样式提供了漂亮的表格:

    <table class="table table-striped table-bordered table-condensed">
      ...
    </table>
    

    【讨论】:

      【解决方案2】:

      Twitter 引导表可以进行样式化和精心设计。你可以在你的桌子上添加一些类来设计你的桌子,它会看起来不错。您可以在数据报告、显示信息等上使用它。

      您可以使用:

      basic table
      Striped rows
      Bordered table
      Hover rows
      Condensed table
      Contextual classes
      Responsive tables
      

      条纹行表:

          <table class="table table-striped" width="647">
          <thead>
          <tr>
          <th>#</th>
          <th>Name</th>
          <th>Address</th>
          <th>mail</th>
          </tr>
          </thead>
          <tbody>
          <tr>
          <td>1</td>
          <td>Thomas bell</td>
          <td>Brick lane, London</td>
          <td>thomas@yahoo.com</td>
          </tr>
          <tr>
          <td height="29">2</td>
          <td>Yan Chapel</td>
          <td>Toronto Australia</td>
          <td>Yan@yahoo.com</td>
          </tr>
          <tr>
          <td>3</td>
          <td>Pit Sampras</td>
          <td>Berlin, Germany</td>
          <td>Pit @yahoo.com</td>
          </tr>
          </tbody>
          </table>
      

      精简表:

      压缩表需要添加 class class=”table table-condensed” 。

          <table class="table table-condensed" width="647">
          <thead>
          <tr>
          <th>#</th>
          <th>Sample Name</th>
          <th>Address</th>
          <th>Mail</th>
          </tr>
          </thead>
          <tbody>
          <tr>
          <td>1</td>
          <td>Thomas bell</td>
          <td>Brick lane, London</td>
          <td>thomas@yahoo.com</td>
          </tr>
          <tr>
          <td height="29">2</td>
          <td>Yan Chapel</td>
          <td>Toronto Australia</td>
          <td>Yan@yahoo.com</td>
          </tr>
          <tr>
          <td>3</td>
          <td>Pit Sampras</td>
          <td>Berlin, Germany</td>
          <td>Pit @yahoo.com</td>
          </tr>
          <tr>
          <td></td>
          <td colspan="3" align="center"></td>
          </tr>
          </tbody>
          </table>
      

      参考:http://twitterbootstrap.org/twitter-bootstrap-table-example-tutorial

      【讨论】:

        【解决方案3】:

        您还可以应用 TR 类:信息、错误、警告或成功。

        【讨论】:

          【解决方案4】:

          只是另一个好看的桌子。我添加了“table-hover”类,因为它提供了很好的悬停效果。

             <h3>NATO Phonetic Alphabet</h3>    
             <table class="table table-striped table-bordered table-condensed table-hover">
             <thead>
              <tr> 
                  <th>Letter</th>
                  <th>Phonetic Letter</th>
          
              </tr>
              </thead>
            <tr>
              <th>A</th>
              <th>Alpha</th>
          
            </tr>
            <tr>
              <td>B</td>
              <td>Bravo</td>
          
            </tr>
            <tr>
              <td>C</td>
              <td>Charlie</td>
          
            </tr>
          
          </table>
          

          【讨论】:

            【解决方案5】:

            bootstrap 为 table 提供了各种类

             <table class="table"></table>
             <table class="table table-bordered"></table>
             <table class="table table-hover"></table>
             <table class="table table-condensed"></table>
             <table class="table table-responsive"></table>
            

            【讨论】:

              【解决方案6】:

              您可以将上下文类添加到每一行,如下所示:

              <tr class="table-success"></tr>
              <tr class="table-error"></tr>
              <tr class="table-warning"></tr>
              <tr class="table-info"></tr>
              <tr class="table-danger"></tr>
              

              您也可以将它们添加到与上述相同的表数据中

              您可以通过将类设置为 table-sm 等来设置表格大小。

              您可以添加自定义类并添加自己的样式:

              <table class="table">
                <thead style = "color:red;background-color:blue">
                  <tr>
                    <th></th>
                    <th>First Name</th>
                    <th>Last Name</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>   
                    <td>Asdf</td>
                    <td>qwerty</td>
                  </tr>
                </tbody>
              </table>
              

              这样您可以添加自定义样式。我已经展示了内联样式,例如它是如何工作的,你可以添加类并在你的 CSS 中调用它们。

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 2017-11-07
                • 2014-01-10
                • 1970-01-01
                • 2013-01-05
                • 2023-03-16
                • 2011-12-26
                • 1970-01-01
                相关资源
                最近更新 更多