Bootstrap-Table

 

.table

Alternate Text

<!DOCTYPE html>
<html>
                            <head>
                            <meta name="viewport" content="width=device-width, initial-scale=1">
                            <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
                            </head>

                            <body>
                            <div class="container">
                            <h2>Table</h2>
                            <p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>            
                            <table class="table">
                            <thead>
                            <tr>
                            <th>#</th>
                            <th>Firstname</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                            <td>1</td>
                            <td>Anna</td>
                            </tr>
                            <tr>
                            <td>2</td>
                            <td>Debbie</td>
                            </tr>
                            <tr>
                            <td>3</td>
                            <td>John</td>
                            </tr>
                            </tbody>
                            </table>
                            </div>

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
                            <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
                            </body>

</html>

為一般的table樣式

 

table-striped

Alternate Text

<!DOCTYPE html>
<html>
                            <head>
                            <meta name="viewport" content="width=device-width, initial-scale=1">
                            <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
                            </head>

                            <body>
                            <div class="container">
                            <h2>Table</h2>    
                            <p>The .table-striped class adds zebra-striping to any table row within tbody (not available in IE8):</p>                  
                            <table class="table table-striped">
                            <thead>
                            <tr>
                            <th>#</th>
                            <th>Firstname</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                            <td>1</td>
                            <td>Anna</td>
                            </tr>
                            <tr>
                            <td>2</td>
                            <td>Debbie</td>
                            </tr>
                            <tr>
                            <td>3</td>
                            <td>John</td>
                            </tr>
                            </tbody>
                            </table>
                            </div>

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
                            <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
                            </body>

</html>

為斑馬條紋的table,另外可参考CSS的CSS3 :nth-of-type() Selector

 

table-hover

Alternate Text

<!DOCTYPE html>
<html>
                            <head>
                            <meta name="viewport" content="width=device-width, initial-scale=1">
                            <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
                            </head>

                            <body>
                            <div class="container">
                            <h2>Table</h2>
                            <p>The .table-hover class enables a hover state on table rows within a tbody:</p>                              
                            <table class="table table-hover">
                            <thead>
                            <tr>
                            <th>#</th>
                            <th>Firstname</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                            <td>1</td>
                            <td>Anna</td>
                            </tr>
                            <tr>
                            <td>2</td>
                            <td>Debbie</td>
                            </tr>
                            <tr>
                            <td>3</td>
                            <td>John</td>
                            </tr>
                            </tbody>
                            </table>
                            </div>

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
                            <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
                            </body>

</html>

當滑鼠移到該table的row上面時「反灰」

 

table-condensed

Alternate Text

<!DOCTYPE html>
<html>
                            <head>
                            <meta name="viewport" content="width=device-width, initial-scale=1">
                            <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
                            </head>

                            <body>
                            <div class="container">
                            <h2>Table</h2>
                            <p>The .table-condensed class makes a table more compact by cutting cell padding in half:</p>                                    
                            <table class="table table-condensed">
                            <thead>
                            <tr>
                            <th>#</th>
                            <th>Firstname</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                            <td>1</td>
                            <td>Anna</td>
                            </tr>
                            <tr>
                            <td>2</td>
                            <td>Debbie</td>
                            </tr>
                            <tr>
                            <td>3</td>
                            <td>John</td>
                            </tr>
                            </tbody>
                            </table>
                            </div>

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
                            <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
                            </body>

</html>

讓表格間距更緊湊一些

 

active

Alternate Text

<!DOCTYPE html>
<html>
                            <head>
                            <meta name="viewport" content="width=device-width, initial-scale=1">
                            <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
                            </head>

                            <body>
                            <div class="container">
                            <h2>Table</h2>
                            <p>The .active class applies the hover color to a particular row or cell:</p>                                        
                            <table class="table">
                            <thead>
                            <tr>
                            <th>#</th>
                            <th>Firstname</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr class="active">
                            <td>1</td>
                            <td>Anna</td>
                            </tr>
                            <tr>
                            <td>2</td>
                            <td>Debbie</td>
                            </tr>
                            <tr>
                            <td>3</td>
                            <td>John</td>
                            </tr>
                            </tbody>
                            </table>
                            </div>

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
                            <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
                            </body>

</html>

例如指定tbody的第一個row為active則該row反灰

 

Alternate Text

<!DOCTYPE html>
<html>
                            <head>
                            <meta name="viewport" content="width=device-width, initial-scale=1">
                            <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
                            </head>

                            <body>
                            <div class="container">
                            <h2>Table</h2>
                            <p>The .success class indicates a successful or positive action:</p>                                                  
                            <table class="table">
                            <thead>
                            <tr>
                            <th>#</th>
                            <th>Firstname</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr class="success">
                            <td>1</td>
                            <td>Anna</td>
                            </tr>
                            <tr>
                            <td>2</td>
                            <td>Debbie</td>
                            </tr>
                            <tr>
                            <td>3</td>
                            <td>John</td>
                            </tr>
                            </tbody>
                            </table>
                            </div>

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
                            <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
                            </body>

</html>

指定該row為success樣式

 

info

Alternate Text

<!DOCTYPE html>
<html>
                            <head>
                            <meta name="viewport" content="width=device-width, initial-scale=1">
                            <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
                            </head>

                            <body>
                            <div class="container">
                            <h2>Table</h2>
                            <p>The .info class indicates a neutral informative change or action:</p>                                                            
                            <table class="table">
                            <thead>
                            <tr>
                            <th>#</th>
                            <th>Firstname</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr class="info">
                            <td>1</td>
                            <td>Anna</td>
                            </tr>
                            <tr>
                            <td>2</td>
                            <td>Debbie</td>
                            </tr>
                            <tr>
                            <td>3</td>
                            <td>John</td>
                            </tr>
                            </tbody>
                            </table>
                            </div>

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
                            <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
                            </body>

</html>

指定該row為info樣式

 

warning

Alternate Text

<!DOCTYPE html>
<html>
                            <head>
                            <meta name="viewport" content="width=device-width, initial-scale=1">
                            <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
                            </head>

                            <body>
                            <div class="container">
                            <h2>Table</h2>
                            <p>The .info class indicates a neutral informative change or action:</p>                                                            
                            <table class="table">
                            <thead>
                            <tr>
                            <th>#</th>
                            <th>Firstname</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr class="warning">
                            <td>1</td>
                            <td>Anna</td>
                            </tr>
                            <tr>
                            <td>2</td>
                            <td>Debbie</td>
                            </tr>
                            <tr>
                            <td>3</td>
                            <td>John</td>
                            </tr>
                            </tbody>
                            </table>
                            </div>

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
                            <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
                            </body>

</html>

指定該row為warning樣式

 

danger

Alternate Text

<!DOCTYPE html>
<html>
                            <head>
                            <meta name="viewport" content="width=device-width, initial-scale=1">
                            <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
                            </head>

                            <body>
                            <div class="container">
                            <h2>Table</h2>
                            <p>The .info class indicates a neutral informative change or action:</p>                                                            
                            <table class="table">
                            <thead>
                            <tr>
                            <th>#</th>
                            <th>Firstname</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr class="danger">
                            <td>1</td>
                            <td>Anna</td>
                            </tr>
                            <tr>
                            <td>2</td>
                            <td>Debbie</td>
                            </tr>
                            <tr>
                            <td>3</td>
                            <td>John</td>
                            </tr>
                            </tbody>
                            </table>
                            </div>

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
                            <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
                            </body>

</html>

指定該row為danger樣式