Utilizing Bootsrap 4's grid system to mimic a table layout with four columns

I've been experimenting with the bootstrap 4 grid to create a table-like layout. By using the following CSS code, I was able to achieve the desired behavior:

.data-table{
    display : table ;        
    padding : 0em; 
}

.data-table > .row{
  display : table-row ; 
}

.data-table > .row > * {
  display : table-cell ; 
  white-space : nowrap ; 
}

The .data-table is contained within a .container div.

For the column width, I used the "col-auto" class to adjust it based on the data inside. Everything was working smoothly until I attempted to hide some columns on medium to small devices using the "d-none d-lg-block" classes in bootstrap 4. This caused the entire table layout to become buggy. The issue seems to arise when applying this class to two adjacent columns. My current setup looks like this:

<div class "col-auto d-none d-lg-block"><!--code--></div> 
<div class "col-auto">--code--</div> 
<div class "col-auto d-none d-lg-block"><!--code--></div> 

While this setup functions well for the most part, I'm now seeking solutions on how to resolve these bugs and explore alternative approaches.

Answer №1

The issue here lies in the manipulation of the display attribute, causing it to deviate from its intended functionality as defined by bootstrap. A more effective approach would be to utilize a standard bootstrap table, incorporate an additional class for the cells that need to be hidden, and employ @media queries to effectively conceal them. If we assume the class is named md-hide, the corresponding CSS code would appear as follows:

@media screen and (max-width: 992px) {
   .md-hide {
      display: none;
   }
}

This strategy should provide the desired outcome.

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

Lagging performance occurs as the size of HTML table increases

I am facing a challenge with my HTML table as it takes longer to load when the row count is high. I need to display a table with around 50000 rows on my webpage using basic HTML and ASP.NET C#. <div class="panel panel-primary"> ...

Inquiries regarding jQuery's functionality and efficiency

I was wondering about the best way to improve performance? Would it be more efficient to have two images written in HTML, one visible and one hidden, and then use jQuery to toggle their display (hiding the visible one and showing the hidden one)? <img ...

The options for answering (True, False, Yes, and No) are not currently visible

I am struggling with displaying buttons for "True", "False", "Yes", and "No" in an appended row. Here is the application: Application To use the application, follow these steps: 1. Open the application and click on the green plus button. A modal window ...

How to center align two child divs within a parent div using flexbox in Bootstrap 5

I'm attempting to center two child divs within a parent div, but they're displaying side by side in the center. html <div class="container mt-5 box d-flex justify-content-center align-items-center"> <i class="fa-solid f ...

Dropdown element with PrimeNG adorned with a span

I am trying to create a simple form with text inputs and dropdowns. I have successfully implemented the textInput, but I am struggling with the dropdowns. Below is the code that I have so far: <div class="p-grid p-dir-col p-offset-2"> ...

Comparing the use of jQuery's data() method versus directly accessing attributes with native JavaScript using get

I want to retrieve general information from my website using javascript. I have a few different options available: I could use an html element: <input type="hidden" value="MyValue"/> Another option is to use a custom attribute in an existing h ...

My goal is to retrieve and print the duplicated values only once from an associative array

Given an associative array, I need to print all the department names without any repetitions. <h3>2. List out all department names</h3> <div class="all"> </div> Here is my JavaScript code: var employee=[{"firstName":"Zahir","last ...

Unable to load circles on page refresh with amCharts Maps

I am experiencing an issue with the functionality of my amCharts maps. Whenever I refresh the page, the circles that are supposed to be displayed disappear. However, when I zoom in, the circles reappear. This problem has me puzzled, and I'm not sure ...

JavaScript code to make titles slide in as the user scrolls

Looking for a better way to make all titles slide in upon scrolling instead of coding individually? Consider using a forEach loop! Here's how you can modify the code below: function slideInLeft() { document.querySelectorAll('.subtitle-left ...

The blur function in jQuery is not functioning as expected

I'm facing an issue where only the first of my 3 .blur's is working. Here is the jQuery code snippet: <script type='text/javascript'> $(document).ready(function() { $("#user_name").blur(function() { if ($( ...

Swap out a button for another using JavaScript

I am facing a challenge where I need to replace an active button with a deactivate button. The issue is that when I click on the active button, it does change to the deactivate button as expected. However, clicking again does not switch it back to the acti ...

Can jQuery version 1.3.0 be used to enable $.mobile.pageCreate on Webkit browsers?

After numerous attempts to address this issue, it finally occurred to me that the problem stemmed from using the jQuery 1.3.0 library. My goal is to create a dialog on a webpage without requiring user interaction using jQuery mobile. Surprisingly, it work ...

What is the best way to create flexible Bootstrap 3 columns with varying heights?

I'm struggling to remove space and create a flex column .col-md-5 with varying heights. Despite trying various solutions found on Google, I still can't get it to function properly. The current outcome is not as expected. https://i.sstatic.net/fc ...

Effortlessly switch between multiple divs with jQuery

I am working on a functionality where multiple divs should be displayed or hidden based on the button clicked. Initially, all buttons and divs are visible. Upon clicking a button, only the corresponding div should be visible. Subsequent clicks on other but ...

What's the best way to enable touch scrolling for items within a div container?

I am in the process of creating a code snippet that will allow users to scroll through items within a div, similar to a spinning wheel or slot machine. While I am aware of an existing solution for iPhone and iPod, I want to develop a simpler, more streamli ...

Toggle the tooltip to reveal a hidden div by clicking, and then click again to close it

I've been working on implementing a toggle div with a tooltip. The issue I'm facing is that the tooltip initially displays "Click to open", but after opening the toggle, it should change to "Click to close". Can someone assist me in achieving thi ...

learn the technique I use to incorporate a see-through background in HTML

Is there a way to enclose a specific section of text with a background to improve readability, considering that changing the text color is not the preferred solution due to an existing background image? ...

Trigger event upon variable modification

Currently, I am working on a school project that involves creating a website where users can listen to music together. I have implemented a button that allows the user to listen to the same song another user is currently playing at the right position. Howe ...

Tips for including a personalized CSS class in the datepicker control

Is there a method to incorporate a personalized css class title into the daterangepicker ? I want to utilize my custom styles based on my class title. For example, $('.dpick').daterangepicker( { customClass: 'my-css', // The class name ...

personalized styles based on user preferences

My website features a gaming section where users can view quick status updates of their stats using colors like blue, red, and green. I am looking to generate something similar for each user. Here is what I have so far: <style> .box2 { height: ...