wottpal wottpal - 6 months ago 18
HTML Question

Twitter Bootstrap table width full width but content centered

I have a table like this (included bootstrap):

<table class="table table-hover">
<tbody>
<tr><td>Head1</td><td>content1.1</td></tr>
<tr><td></td><td>content1.2</td></tr>
<tr><td></td><td>content1.3</td></tr>
<tr><td>Head2</td><td>content2</td></tr>
<tr><td>Head3</td><td>content3</td></tr>
</tbody>
</table>


I want the table lines over the full width of it's container but the two cells with header and content should be centered.. I've tried to describe it in an image:

I cant upload the image here, so I've done it somewhere else:

See image for more description

Answer

I have shown only two rows (tr). You can add as many rows as you want.

HTML:

    <table class="table table-hover">
   <tbody>
      <tr>
         <td>&nbsp;</td>
         <td>Head1</td>
         <td>content1</td>
         <td>&nbsp;</td>
      </tr> 
      <tr>
         <td>&nbsp;</td>
         <td>Head2</td>
         <td>content2</td>
         <td>&nbsp;</td>
      </tr>      
   </tbody>
</table>

CSS:

table.table.table-hover{ width:100%; }
table.table.table-hover tr td{ width:25% }

DEMO

Hope you will find this useful :)