Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I highlight an HTML table column with Bootstrap

I am using bootstrap and have created a table in which I need columns grouped together. Is there any bootstrap options that I can use? I am willing to write my own CSS to do it, but I would rather not if there is a built in bootstrap way to do it.

For example, in the table below I would want the Current columns with one color background and the New columns to have another.

http://jsfiddle.net/75v7W/

<table>     <thead>         <tr>             <td></td>             <td colspan="2" style="text-align: center;">Current</td>             <td colspan="2" style="text-align: center;">New</td>         </tr>         <tr>             <th>ID</th>             <th>First Name</th>             <th>Last Name</th>             <th>Fisrt Name</th>             <th>Last Name</th>         </tr>     </thead>     <tbody>         <tr>             <td>1</td>             <td>John</td>             <td>Bauer</td>             <td>Jack</td>             <td>Bauer</td>         </tr>     </tbody> </table> 

UPDATE: I have achieved something of what I am looking for using colgroup and, alas, custom CSS (though not very much) : http://jsfiddle.net/75v7W/4/

like image 772
wilsjd Avatar asked Jun 06 '13 16:06

wilsjd


People also ask

How do I add color to a table column in HTML?

Cell background colors are set by applying the bgcolor attribute to a <tr> tag (to color the row) or to a <td> tag (to color the cell).

How do I highlight a column in a table?

You can also click anywhere in the table column, and then press CTRL+SPACEBAR, or you can click the first cell in the table column, and then press CTRL+SHIFT+DOWN ARROW. Note: Pressing CTRL+SPACEBAR once selects the table column data; pressing CTRL+SPACEBAR twice selects the entire table column.

How do you highlight a table in HTML?

Highlight Table Row using CSS. You can use CSS without any javascript to make the row of a table highlight on hover. All it requires is that the use the pseudo class :hover to add the effect to whatever html element you choose.

How do I change the background-color of a table in bootstrap?

Using pre-defined classes, we can change the color of table cells and table rows. In order to change the color of the table row, we need to specify in <tr> tag with the required class & for changing the color of the table row then specify it inside <td> tag with the required class.


1 Answers

I achieved something of what I am looking for using colgroup and, alas, custom CSS (though not very much): http://jsfiddle.net/75v7W/4/

Note: For the background-colors below, I pulled from the success, error, etc. from the default colors in the bootstrap.css. If you have customized your bootstrap.css, these specific colors may not work for you.

CSS

colgroup col.success {   background-color: #dff0d8; } colgroup col.error {   background-color: #f2dede; } colgroup col.warning {   background-color: #fcf8e3; } colgroup col.info {   background-color: #d9edf7; }    

TABLE

<table class="table table-condensed">     <colgroup>         <col>         <col span="2" class="info">         <col span="2" class="success">     </colgroup>     <thead>         <tr>             <td></td>             <td colspan="2" style="text-align: center;">Current</td>             <td colspan="2" style="text-align: center;">New</td>         </tr>         <tr>             <th>ID</th>             <th>First Name</th>             <th>Last Name</th>             <th>Fisrt Name</th>             <th>Last Name</th>         </tr>     </thead>     <tbody>         <tr>             <td>1</td>             <td>John</td>             <td>Bauer</td>             <td>Jack</td>             <td>Bauer</td>         </tr>     </tbody> </table> 
like image 200
wilsjd Avatar answered Oct 10 '22 07:10

wilsjd