Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Bootstrap 3 grid system with table component?

Tags:

I have started a migration to grid system using Bootstrap 3, but the examples in the documentation are all using DIVs: http://getbootstrap.com/css/#grid

I made a somewhat redundant code that mixes the DIV classes with TABLE tags/classes: http://getbootstrap.com/css/#tables

The problem is that the layout dobles the borders and I think the should be a better way of doing that. Any recommendations on that?

An example code in Fiddle: http://jsfiddle.net/7g8nV/1/

<div class="table-responsive">   <table class="table table-bordered">    <tr class="row">     <td class="field-label col-md-3 active">       <label>Field 1:</label>     </td>     <td class="col-md-9">       Value 1     </td>   </tr>   <tr class="row">     <td class="field-label col-md-3 active">       <label>Field 2:</label>     </td>     <td class="col-md-9">       Value 2     </td>   </tr>   <tr class="row">     <td class="field-label col-md-3 active">       <label>Field 3:</label>     </td>     <td class="col-md-9">       Value 3     </td>   </tr> </table> </div> 

Thanks in advance.

like image 524
staticdev Avatar asked Sep 04 '13 12:09

staticdev


People also ask

Does Bootstrap 3 have a grid system?

The Bootstrap 3 grid system has four tiers of classes: xs (phones), sm (tablets), md (desktops), and lg (larger desktops). You can use nearly any combination of these classes to create more dynamic and flexible layouts.

Can you use Bootstrap with grid?

With Bootstrap 5, we've added the option to enable a separate grid system that's built on CSS Grid, but with a Bootstrap twist. You still get classes you can apply on a whim to build responsive layouts, but with a different approach under the hood.

How do I make 3 columns in Bootstrap 4?

Three Equal ColumnsUse the . col class on a specified number of elements and Bootstrap will recognize how many elements there are (and create equal-width columns). In the example below, we use three col elements, which gets a width of 33.33% each.


1 Answers

Remove the row class from your <tr> elements. That class makes a non-table-row element look like a table-row and adds some styles that break a standard <tr>. You can still use the "col" classes like normal:

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">    <table class="table table-bordered">     <tr>      <td class="field-label col-xs-3 active">        <label>Field 1:</label>      </td>      <td class="col-md-9">        Value 1      </td>    </tr>    <tr>      <td class="field-label col-xs-3 active">        <label>Field 2:</label>      </td>      <td class="col-md-9">        Value 2      </td>    </tr>    <tr>      <td class="field-label col-xs-3 active">        <label>Field 3:</label>      </td>      <td class="col-md-9">        Value 3      </td>    </tr>  </table>
like image 161
Ross Allen Avatar answered Sep 24 '22 03:09

Ross Allen