ตารางพื้นฐาน
สำหรับการสร้างตารางแบบพื้นฐานโดยใช้ Bootstrap จะมีเพียงเส้นบรรทัดกั้นแต่ละแถวเท่านั้นโดยเพียงเรียกใช้งาน .table
| # | First Name | Last Name | Username | 
|---|---|---|---|
| 1 | Mark | Otto | @mdo | 
| 2 | Jacob | Thornton | @fat | 
| 3 | Larry | the Bird | 
คำสั่ง HTML
<table class="table">
    <caption>คำอธิบายตาราง</caption>
    <thead>
    <tr>
        <th>#</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Username</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <th scope="row">1</th>
        <td>Mark</td>
        <td>Otto</td>
        <td>@mdo</td>
    </tr>
    <tr>
        <th scope="row">2</th>
        <td>Jacob</td>
        <td>Thornton</td>
        <td>@fat</td>
    </tr>
    <tr>
        <th scope="row">3</th>
        <td>Larry</td>
        <td>the Bird</td>
        <td>@twitter</td>
    </tr>
    </tbody>
</table>
ตารางสลับลาย (Striped)
เพิ่ม class .table-striped ในการสลับแถวให้เป็นแบบม้าลาย ภายใน tag <tbody>
| # | First Name | Last Name | Username | 
|---|---|---|---|
| 1 | Mark | Otto | @mdo | 
| 2 | Jacob | Thornton | @fat | 
| 3 | Larry | the Bird | 
คำสั่ง HTML
<table class="table table-striped">
    <caption>คำอธิบายตาราง</caption>
    <thead>
    <tr>
        <th>#</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Username</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <th scope="row">1</th>
        <td>Mark</td>
        <td>Otto</td>
        <td>@mdo</td>
    </tr>
    <tr>
        <th scope="row">2</th>
        <td>Jacob</td>
        <td>Thornton</td>
        <td>@fat</td>
    </tr>
    <tr>
        <th scope="row">3</th>
        <td>Larry</td>
        <td>the Bird</td>
        <td>@twitter</td>
    </tr>
    </tbody>
</table>
ตารางแบบมีเส้นขอบ (Bordered)
เพิ่ม class .table-bordered ในการสร้างเส้นขอบในทุกๆ ด้าน และทุกๆ ช่องตาราง
| # | First Name | Last Name | Username | 
|---|---|---|---|
| 1 | Mark | Otto | @mdo | 
| 2 | Jacob | Thornton | @fat | 
| 3 | Larry | the Bird | 
คำสั่ง HTML
<table class="table table-bordered">
    <caption>คำอธิบายตาราง</caption>
    <thead>
    <tr>
        <th>#</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Username</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <th scope="row">1</th>
        <td>Mark</td>
        <td>Otto</td>
        <td>@mdo</td>
    </tr>
    <tr>
        <th scope="row">2</th>
        <td>Jacob</td>
        <td>Thornton</td>
        <td>@fat</td>
    </tr>
    <tr>
        <th scope="row">3</th>
        <td>Larry</td>
        <td>the Bird</td>
        <td>@twitter</td>
    </tr>
    </tbody>
</table>
เน้นเมื่อวางเมาส์ (Hover)
เพิ่ม class .table-hover เมื่อต้องการให้ตารางมีแถบเมื่อนำเมาส์วาง (Hover)
| # | First Name | Last Name | Username | 
|---|---|---|---|
| 1 | Mark | Otto | @mdo | 
| 2 | Jacob | Thornton | @fat | 
| 3 | Larry | the Bird | 
คำสั่ง HTML
<table class="table table-hover">
    <caption>คำอธิบายตาราง</caption>
    <thead>
    <tr>
        <th>#</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Username</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <th scope="row">1</th>
        <td>Mark</td>
        <td>Otto</td>
        <td>@mdo</td>
    </tr>
    <tr>
        <th scope="row">2</th>
        <td>Jacob</td>
        <td>Thornton</td>
        <td>@fat</td>
    </tr>
    <tr>
        <th scope="row">3</th>
        <td>Larry</td>
        <td>the Bird</td>
        <td>@twitter</td>
    </tr>
    </tbody>
</table>
ตารางแบบรวมหลายๆ แบบ
เราสามารถกำหนด class ให้กับตารางได้หลายๆ แบบพร้อมกัน
| # | First Name | Last Name | Username | 
|---|---|---|---|
| 1 | Mark | Otto | @mdo | 
| 2 | Jacob | Thornton | @fat | 
| 3 | Larry | the Bird | 
คำสั่ง HTML
<table class="table table-striped table-bordered table-hover">
    <caption>คำอธิบายตาราง</caption>
    <thead>
    <tr>
        <th>#</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Username</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <th scope="row">1</th>
        <td>Mark</td>
        <td>Otto</td>
        <td>@mdo</td>
    </tr>
    <tr>
        <th scope="row">2</th>
        <td>Jacob</td>
        <td>Thornton</td>
        <td>@fat</td>
    </tr>
    <tr>
        <th scope="row">3</th>
        <td>Larry</td>
        <td>the Bird</td>
        <td>@twitter</td>
    </tr>
    </tbody>
</table>
ตารางแบบกระชับ (Condensed)
เพิ่ม class .table-condensed เพื่อกระชับตารางตามข้อมูล โดยเป็นการลด cell-padding ลงครึ่งหนึ่ง และย่อตารางตามข้อมูล
| # | First Name | Last Name | Username | 
|---|---|---|---|
| 1 | Mark | Otto | @mdo | 
| 2 | Jacob | Thornton | @fat | 
| 3 | Larry | the Bird | 
คำสั่ง HTML
<table class="table table-condensed">
    <caption>คำอธิบายตาราง</caption>
    <thead>
    <tr>
        <th>#</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Username</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <th scope="row">1</th>
        <td>Mark</td>
        <td>Otto</td>
        <td>@mdo</td>
    </tr>
    <tr>
        <th scope="row">2</th>
        <td>Jacob</td>
        <td>Thornton</td>
        <td>@fat</td>
    </tr>
    <tr>
        <th scope="row">3</th>
        <td>Larry</td>
        <td>the Bird</td>
        <td>@twitter</td>
    </tr>
    </tbody>
</table>
ตารางแบบ Responsive
สามารถใช้ class .table-responsive ใน tag <div> ซึ่งจะแสดง scroll ด้านล่างเมื่อหน้าจอมีขนาดน้อยกว่าขนาดตาราง
| # | Table heading | Table heading | Table heading | Table heading | Table heading | Table heading | 
|---|---|---|---|---|---|---|
| 1 | Table cell | Table cell | Table cell | Table cell | Table cell | Table cell | 
| 2 | Table cell | Table cell | Table cell | Table cell | Table cell | Table cell | 
| 3 | Table cell | Table cell | Table cell | Table cell | Table cell | Table cell | 
คำสั่ง HTML
<div class="table-responsive">
    <table class="table table-bordered">
        <thead>
        <tr>
            <th>#</th>
            <th>Table heading</th>
            <th>Table heading</th>
            <th>Table heading</th>
            <th>Table heading</th>
            <th>Table heading</th>
            <th>Table heading</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <th scope="row">1</th>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
        </tr>
        <tr>
            <th scope="row">2</th>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
        </tr>
        <tr>
            <th scope="row">3</th>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
        </tr>
        </tbody>
    </table>
</div>
 
                             
                        
ความคิดเห็น