webmarjan
webmarjan

Reputation: 43

Bootstrap table colspan rowspan issue

I would like to create my table to work like this: my desired table

I have tried the following code but it does not work:

<section class="signa-table-section clearfix">
   <div class="container">
      <div class="row">
         <div class="col-lg">
            <table class="table table-responsive table-bordered">
               <thead>
                  <tr>
                     <th>Entry</th>
                     <th>Sl</th>
                     <th colspan="3">Tp</th>
                     <th>Tp</th>
                  </tr>
               </thead>
               <tbody>
                  <tr>
                     <td>Mark</td>
                     <td>Otto</td>
                     <td>@mdo</td>
                     <td>Mark</td>
                     <td>Otto</td>
                  </tr>
                  <tr>
                     <td>Mark</td>
                     <td>Otto</td>
                     <td>@mdo</td>
                     <td>Mark</td>
                     <td>Otto</td>
                  </tr>
                  <tr>
                     <td>Mark</td>
                     <td>Otto</td>
                     <td>@mdo</td>
                     <td>Mark</td>
                     <td>Otto</td>
                  </tr>
               </tbody>
            </table>
         </div>
      </div>
   </div>
</section>

Upvotes: 5

Views: 16935

Answers (2)

M0nst3R
M0nst3R

Reputation: 5283

In order to achieve the desired division inside your table head, you need to basically create a new table within the head and divide that one.

Your <th> would look like the following:

<th colspan="3" class="custom-header">
    <table class="table table-responsive">
        <thead>
            <tr>
                <th colspan="3" class="last">Tp</th>
            </tr>
            <tr>
                <th>Tp1</th>
                <th>Tp2</th>
                <th class="last">Tp3</th>
            </tr>
        </thead>
    </table>
</th>

Then you need to play around with CSS until the result looks just right, you want to tamper with margin, padding, border and width. Here is a codepen with a proposed solution.

Upvotes: 0

GGO
GGO

Reputation: 2748

Replace inside your <thead> by :

<tr>
   <th rowspan="2">Entry</th>
   <th rowspan="2">Sl</th>
   <th colspan="3">Tp</th>
</tr>
<tr>
   <th>Tp</th>
   <th>Tp</th>
   <th>Tp</th>
</tr>

Upvotes: 1

Related Questions