Creating stylish grid-based tables in Bootstrap 4

I'm currently updating the front-end of an application by utilizing bootstrap 4. I've encountered tables in certain sections of the application that I want to replace, so I'm converting them into a .row/.col grid system. While bootstrap provides styling options for tables, I'm struggling to find similar options for rows and columns. The table in the snippet automatically receives styling, but how can I achieve the same look using a grid system?

Here's an example:

<!DOCTYPE html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<table class="table table-striped">
     <thead class="thead-light">
          <th>Thing one</th>
          <th>Thing two</th>
          <th>Thing Three</th>
     </thead>
     <tbody>
        <tr>
          <td>One</td>
          <td>Two</td>
          <td>Three</td>
        </tr>
        <tr>
          <td>Four</td>
          <td>Five</td>
          <td>Six</td>
        </tr>
        <tr>
          <td>Seven</td>
          <td>Eight</td>
          <td>Nine</td>
        </tr>
     </tbody>
</table>

<div class="container">
<div class="row">
    <div class="col">
    Thing one
    </div>
    <div class="col">
    Thing two
    </div>
    <div class="col">
    Thing three
    </div>
</div>
    <div class="row">
      <div class="col">
        One
      </div>
      <div class="col">
        Two
      </div>
      <div class="col">
        Three
      </div>
    </div>
    <div class="row">
      <div class="col">
        Four
      </div>
      <div class="col">
        Five
      </div>
      <div class="col">
        Six
      </div>
    </div>
      <div class="row">
        <div class="col">
          Seven
        </div>
        <div class="col">
          Eight
        </div>
        <div class="col">
          Nine
        </div>
      </div>
    </div>
  </body>
    

Answer №1

To achieve the desired look, you can incorporate CSS in your code...

.grid-striped .row:nth-of-type(odd) {
    background-color: rgba(0,0,0,.05);
}

Alternatively, you can utilize the Bootstrap 4 utilities such as font-weight-bold, bg-light, but keep in mind that these will require individual implementation and won't automatically alternate odd rows like the CSS method mentioned above.

Check out the demonstration:


Additionally, don't forget that table columns can be sized using the grid system

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

Using the "checked" attribute in an HTML input to hide content with CSS when blocks are positioned in different

Is there a way to connect input with buttons similar to the code below, or is it impossible without changing the HTML (unless using JS code)? Please don't critique the HTML code, this is just an example from a website, I'm trying to det ...

What is the best way to ensure that each box remains separate and does not overlap with the box next to it?

Just an FYI - styling in React using CSS is quite similar to regular CSS. Each individual box has its own code snippet: export const CardWrapper = styled.div` display: flex; flex-direction: column; align-items: center; border-radius: 4px; backg ...

Utilizing LESS for Mixing

I've been diving into the official LESS documentation (version 1.5) and I'm struggling to grasp how I can import a reference to another CSS file to utilize its content in my own stylesheet. For instance: stylesheet.less @import (reference) "boo ...

Turn off HTML display for Internet Explorer users

I am looking to implement code that will block certain pages for Internet Explorer users, making it accessible only for Google Chrome and Firefox users. Do you have any suggestions on how I can achieve this or if there are existing solutions available? I& ...

Changing innerHTML with HTML generated by a PHP function? (utilizing xajax)

I have managed to successfully update the content inside a DIV using xajax when clicking a link. However, I noticed that it only works when I directly assign HTML within the function itself, not when calling it from another function. Allow me to demonstra ...

"Implementing responsive design with Bootstrap's carousel through media queries

I'm having some trouble creating a basic carousel using bootstrap because the images are not displaying full screen. Do I need to use media queries to achieve this and if so, how can I implement them? <div id="myCarousel" class="carousel slide" da ...

Instructions on connecting something from manifest.json

I've encountered a dilemma while using Webpack with the CleanWebpackPlugin. Since I am utilizing an index.php file, I cannot make use of HtmlWebpackPlugin. After some research, I came across an alternative plugin known as WebpackManifestPlugin. This p ...

Guide to customizing color themes using Twitter Bootstrap 3

Recently, I dove into the world of Twitter Bootstrap 3 without any prior experience with earlier versions. It's been a learning curve, but I managed to set up a WordPress theme using it as the framework. All my elements are in place, but they all see ...

Issue with Laravel project: Views are not updating after code changes

Despite my efforts to clear and refresh everything, my Laravel project is not reflecting the changes. I have attempted clearing the view and deleting files manually. I also ran cache:clear, changed the root folder name, but the project continues to displa ...

Customize Vue Element UI table cell appearance depending on the data

I am utilizing Element UI for my project. How can I dynamically change the color of the rate cell value in the table? I want the color to be red when rate is less than 0, and green when it is greater than or equal to 0. I wonder if the table attribute cel ...

Is there a way to modify the background color with Bootstrap?

While following a Bootstrap tutorial, I stumbled upon an issue that I can't seem to resolve. In my layout, I have an article and a sidebar in a row, with the article taking up 9 columns and the sidebar taking up 3 columns. The background color of the ...

The thickness of the tooltip border appears more pronounced in Microsoft Edge

My table displays a value when I hover over it. In Google Chrome, it appears like this: https://i.sstatic.net/dHTKx.png However, in Microsoft Edge, it looks like this: https://i.sstatic.net/mqNC0.png I haven't made any changes to it, so it seems ...

Bootstrap CSS flexibly decreases the size of the input field on the form

I'm having trouble with Bootstrap-5. When I add the d-flex class to a container, my form inputs and labels shrink. If I remove d-flex, justify-center, and align-items-center from the container class, the form is no longer centered on the page. Adding ...

Using Angular JS to retrieve specific information from a JSON file

I am in the process of developing an AngularJS app that showcases notes. The notes are stored in a note.json file, and the main page of the app only displays a few fields for each note. I want to implement a feature where clicking on a specific note opens ...

Which specific html container or element can be found on the mymsn pages?

When accessing mymsn, users have the ability to personalize the content and layout of their webpage. I am curious about what type of container is being utilized for this customization - does it involve an html element, or perhaps javascript, or something e ...

Is there a way to make a TABLE expand to match the height of its surrounding element? (or, tackling sluggishness in IE with JavaScript)

I am facing a challenge with a web page where I have a table nested inside of a TD tag. Despite the unconventional approach, I need to ensure that the height of the nested table matches the height of the TD cell containing it upon page load. Currently, I a ...

What is the best way to navigate through a complex array in React that includes objects and nested arrays?

I have been working on a JavaScript array that includes subobjects with arrays nested in them. My goal is to iterate through the entire parent object using React. Although I attempted the following approach, unfortunately it did not yield the desired outco ...

Tips for repairing buttons in the CSS container

The buttons in the CSS search-box are not staying fixed as intended. They should be within the search box, but instead, they are protruding out of the panel. I attempted to utilize z-index, but it did not produce the desired outcome. https://i.sstatic.n ...

Discover the Optimal Approach to Implementing Callback Function with JSON Using Javascript and Jquery

I have a function that looks like this : <script> function sticky(json){something here} </script> Now, I would like to utilize Jquery to invoke this function and display its output within a specific div element with the ID of "stickid". H ...

Display the hidden div element when clicked

In my code, I have two div elements as follows: <div class='staticMap'></div> <div class='geolocation-common-map'></div> Initially, the 'geolocation-common-map' div is removed using jQuery when the pa ...