What is the best way to accentuate a column in an HTML table using Bootstrap?

I have implemented a table in my bootstrap project and I am looking to group columns together. Are there any built-in options in bootstrap that allow for this? While I am open to writing custom CSS if necessary, I would prefer to use a native feature in bootstrap.

Specifically, I would like to apply one background color to the Current columns and a different color to the New columns within the table.

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: After some tinkering with colgroup and minimal custom CSS, I was able to achieve a partial solution: http://jsfiddle.net/75v7W/4/

Answer №1

I was able to achieve part of what I was looking for by utilizing the colgroup feature along with some custom CSS (although minimal): http://jsfiddle.net/75v7W/4/

Please note that the background-colors used here are taken from the default color palette in the bootstrap.css file. If you have made modifications to your bootstrap.css, these specific colors may not be suitable.

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>

Answer №2

To enhance the styling, it is recommended to make use of the pre-existing CSS classes in Bootstrap.

Highlighting columns can be achieved using the following method: https://jsfiddle.net/SaraJones/tc4yv52k/

HTML:

<table class="table table-condensed">
  <colgroup>
    <col class="bg-primary"></col>
    <col span="2" class="bg-info"></col>
    <col span="2" class="bg-warning"></col>
  </colgroup>
  <thead>
    <tr>
      <td></td>
      <td colspan="2" class="text-center bg-success">Existing</td>
      <td colspan="2" class="text-center">Newest</td>
    </tr>
    <tr>
      <th>Identification</th>
      <th>Initial Name</th>
      <th>Final Name</th>
      <th>First Name</th>
      <th>Last Name</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>2</td>
      <td>Benjamin</td>
      <td>Franklin</td>
      <td>Alex</td>
      <td>Hamilton</td>
    </tr>
  </tbody>
</table>

You have a choice of using

  • bg-primary
  • bg-success
  • bg-info
  • bg-warning
  • bg-danger

CSS classes for customizing your columns, cells, and more.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

My server is experiencing issues with multiple file uploads in PHP

I'm having trouble with multiple file uploads in PHP. Here is the code snippet and link: <form action="" method="POST" enctype="multipart/form-data> <input type="file" name="files[]" multiple/> <input type="submit"/> Link < ...

The functionality of the Delete and Edit buttons has been disabled

As I am developing a CRUD (Create, Read, Update, Delete) application that involves managing a list of students and their grades, I have encountered issues while trying to implement the delete and edit functionalities on the front end. Specifically, I am st ...

Choosing radio buttons within rows that contain two radio buttons using ngFor

This section showcases HTML code to demonstrate how I am iterating over an array of objects. <div class="row" *ngFor="let item of modules; let i = index;"> <div class="col-md-1 align-center">{{i+1}}</div> <div class="col-md- ...

Utilizing Python for replacing all hyperlinks on an HTML page with local addresses

As someone who is new to working with html pages in python, I am currently attempting to create a basic web-crawler. Having successfully downloaded all the links from the website I am working on, my next goal is to transition to offline functionality by ...

The CSS method will not function properly on Safari when targeting the specific ID

that.displayIcon = that.scrollPosition / that.headerHeight $('#icon').css({'opacity':that.displayIcon}) that.rotateIcon = Math.min(1,that.scrollPosition/that.headerHeight) $('#icon').css({'transform':'rot ...

Displaying Images in VUE JS from an Array

I'm currently working on linking images to an img element from an array of objects. While I've successfully managed to transfer the strings to the HTML elements, I'm facing challenges with displaying the pictures. Any assistance would be gre ...

The jQuery dialog() function is functioning properly on one page, but encountering issues on a different

On one of my web pages, I have successfully implemented a modal dialog using jQuery and jQuery UI. However, when I try to replicate the same setup on another page with identical HTML markup and JavaScript files, I encounter the following errors: Internet ...

Having trouble setting up the sign in and sign up feature on my website using Django

form.py class SignUpForm(forms.Form): name = forms.CharField(max_length=50, required=True) email = forms.EmailField(max_length=100, required=True) password = forms.CharField(max_length=20, required=True) class Si ...

Strange bug affecting jQuery carousel in Internet Explorer

Encountering a strange jQuery problem here - everything seems to be working fine in Safari and Chrome, with just 4 columns being displayed. However, when I try it in IE(10), I only see 1 column and occasionally all 4 columns appear. Check it out here: ...

Create HTML content from a file retrieved from the server

I have been working on a dynamic website project, diving into web development from scratch despite having coding experience in general. As I navigate Angular CLI and Bootstrap, I've come across a fundamental question: Do modern websites house all thei ...

My Bootstrap/Flexbox layout is not behaving as anticipated. Can anyone identify any issues in my code?

I'm currently working on a MVC website that features a login/signup form. I have been trying to utilize bootstrap to format the forms. My main goal is to center the entire form on the screen, but so far I have only been successful in centering it on t ...

What is the optimal tech solution for creating a cross-browser introduction video that is compatible with both iPhone and IE6?

We are in need of an introductory video for our website that must be compatible with all browsers, including Safari on the iPhone and IE6. Our plan is to use a combination of flash with HTML5 fallback or vice versa. Has anyone tried this before? We want t ...

No data coming back from API in JSON format

Can anyone help me figure out what I'm doing wrong? I've been using the sample code from the API documentation (https://github.com/bitmarket-net/api), but the JSON response is empty. All I did was add echo bitmarket_api("info"); and replace the ...

Toggle the visibility of elements (such as a form) with a click of a link - Utilize ajax to

I'm attempting to use jQuery to toggle the visibility of a form. This functionality is triggered by clicking on a specific link... The goal is to hide all links with data-action="edit" and only display the form that follows the clicked link, as there ...

How can I utilize the Facebook API on Tizen to share a video?

Could someone please provide guidance on how to incorporate video uploading functionality into a Tizen application using the Facebook API and HTML5? ...

The combination of sass-loader and Webpack fails to produce CSS output

Need help with setting up sass-loader to compile SCSS into CSS and include it in an HTML file using express.js, alongside react-hot-loader. Check out my configuration file below: var webpack = require('webpack'); var ExtractTextPlugin = require ...

Exploring CSS3 for Creating Stylish Navigation Bars

Currently, I am attempting to design a Navigation bar that resembles the style shown in this image, complete with a drop-down menu feature. Here is how I have structured my menu: <nav> <ul> <li> <a href="/i ...

What is the method for incorporating an additional tab with CSS3 styling?

I stumbled upon a great resource for CSS tabs here. I decided to use the third example called "target." However, as soon as I tried adding a FOURTH tab, everything broke down, including the functionality of the first 3 tabs. You can check out my attempt he ...

Embed the div within images of varying widths

I need help positioning a div in the bottom right corner of all images, regardless of their width. The issue I am facing is that when an image takes up 100% width, the div ends up in the center. How can I ensure the div stays in the lower right corner eve ...

What might be causing the 404 Error to appear on the mobile version of my website?

Currently, I am in the process of developing a static website using HTML, CSS, and Javascript. To add on-scroll animation effects, I have incorporated a plugin known as AOS. In addition, I have included Bootstrap in my project which was installed through n ...