Display a list with collapsed columns on an accordion format for a more compact view on smaller screens

My Bootstrap table setup looks like this:

<table class="table table-striped">
<thead>
<tr>
  <th>Date</th>
  <th>Name</th>
  <th>LastName</th>
  <th>Color</th>
   <th>Car</th>
  <th>Year</th>
  <th>Price</th>

 </tr>
 </thead>
 <tbody>
<tr>
  <td>01/02/2017</td>
  <td>Dan</td>
  <td>Green</td>  
  <td>Blue</td>
  <td>BMW</td>
  <td>2016</td>  
  <td>100k</td>
</tr>
    <tr>
  <td>01/02/2017</td>
  <td>Dan</td>
  <td>Green</td>  
  <td>Blue</td>
  <td>BMW</td>
  <td>2016</td>  
  <td>100k</td>
</tr>
    <tr>
  <td>01/02/2017</td>
  <td>Dan</td>
  <td>Green</td>  
  <td>Blue</td>
  <td>BMW</td>
  <td>2016</td>  
  <td>100k</td>
</tr>
    <tr>
  <td>01/02/2017</td>
  <td>Dan</td>
  <td>Green</td>  
  <td>Blue</td>
  <td>BMW</td>
  <td>2016</td>  
  <td>100k</td>
</tr>
    <tr>
  <td>01/02/2017</td>
  <td>Dan</td>
  <td>Green</td>  
  <td>Blue</td>
  <td>BMW</td>
  <td>2016</td>  
  <td>100k</td>
</tr>

 </tbody>
 </table>

My goal is to change the table display on a breakpoint, for example, when the screen size is smaller than 768px. I'd like it to display like this:

DATE:01/05/2017
car:BMW

Then, when this row is clicked, I want to display:

 Name:Dan
 LastName:Green
 Color:blue
 Year:2016

I'm wondering if it's possible to achieve this using Bootstrap. Alternatively, I'm considering restructuring the elements into a list format instead of a table to adjust their display as cells on smaller screens. I initially thought of creating two different views and toggling them based on screen size, but I'm not sure how to proceed. As a beginner, I'm not familiar with the best practices or how to implement this, preferably using CSS only with JavaScript only required for showing/hiding on click.

For reference, here is a js fiddle Bootstrap Table

Any assistance would be greatly appreciated.

Answer №1

If you're looking to design a layout, consider utilizing the bootstrap grid system. Instead of using traditional tables, bootstrap utilizes div elements and allows you to specify how many columns each div should occupy based on the screen size. To better understand how this works, I recommend checking out this helpful YouTube tutorial that I found very informative: https://www.youtube.com/watch?v=ndr-GbY8hUU

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

Javascript: struggling with focus loss

Looking for a way to transform a navigation item into a search bar upon clicking, and revert back to its original state when the user clicks elsewhere. The morphing aspect is working correctly but I'm having trouble using 'blur' to trigger t ...

Tips for properly removing Bootstrap 4 tooltips when deleting their corresponding DOM element using html()

In my Bootstrap 4 project, I've implemented a live search box that displays results with tooltips for longer descriptions. I've written jQuery scripts to hide the search results and their parent div when certain events occur, like clearing the se ...

The animation unexpectedly resets to 0 just before it begins

Currently, I am developing a coverflow image slider with jQuery animate. However, there are two issues that I am facing. Firstly, when the animation runs for the first time, it starts at `0` instead of `-500`. Secondly, after reaching the end and looping b ...

The customized icon in the Material UI Select component lacks proper vertical centering

Check out this demo link where the dropdown icon is currently not vertically centered. It appears to have extra top padding due to the class "tlm-dropdown-icon", causing it to be off-center. I've tried inspecting the element but couldn' ...

Unable to "clean up" the HTML document

Struggling with utilizing tidy to produce clean html code. My attempt looks like this: tidy -i -utf8 output/page_1530597755.html -b -o test.html However, no output file is being created! Instead, there are numerous warnings and an error message popping u ...

Struggling with Angular 8: Attempting to utilize form data for string formatting in a service, but encountering persistent page reloading and failure to reassign variables from form values

My goal is to extract the zip code from a form, create a URL based on that zip code, make an API call using that URL, and then display the JSON data on the screen. I have successfully generated the URL and retrieved the necessary data. However, I am strug ...

Stop the anchor tag from activating Chrome's status bar

I've been working on a web application with an elastic layout where the footer acts as a toolbar and information display. The footer is always visible at the bottom of the page, without any need for scrolling. We specifically chose this location for t ...

Preventing Form Submission from Redirecting to the Top in an HTML Document with PHP

Recently, I integrated a php form into my html code and changed the file from index.html to index.php. The contact form is functioning perfectly and sending all information as expected. However, after submitting the form, users are receiving the message "T ...

When using percentages in HTML, the height and width of a background picture may not scale correctly

Currently, I am utilizing Webstorm software purely for HTML and CSS without any additional plugins. In my code, there is a <section> element that only has the <html> and tags as its parent elements. This particular section is assigned an ID th ...

The jquery datepicker is malfunctioning after switching to another component

My current setup includes the following versions: jQuery: 3.3.1 jQuery UI: 1.12.1 AngularJS: 6 Here's a snippet of my code: <input id="test" type="text" class="form-control" value=""> In my component (component.t ...

AmCharts Axis renderer mistakenly renders an additional grid line

I have successfully created a basic XYChart using amcharts4. To get rid of the grid lines on the x-axis, I changed the stroke opacity for the x-axis grid to 0 using the following code: xAxis.renderer.grid.template.strokeOpacity = 0; Everything was workin ...

What is the best way to initiate a function upon each page load?

(Apologies in advance for any English mistakes) Hello everyone, I am currently developing a simple Chrome extension to edit certain graphics and text fields on a website (Freshdesk) that cannot be modified directly on the site due to proprietary code. ...

Prevent the cascading of CSS styles on child list items

When constructing my menu, I have organized it using the following HTML structure: <div id=”navigation”> <ul> <li class=”level1”>Top Level Menu item <div class=”sublevel”> <ul> ...

Browsing the website through http://localhost instead of file:// while utilizing node.js

I am currently in the process of familiarizing myself with node.js. Everything appears to be running smoothly when I access the site from file:///C:/.../myfolder/index.html. The jquery and bootstrap files are located in the directories myfolder/css/ and m ...

The form data should persist even if the user switches screens or logs out of the session, ensuring that the information remains intact

As a user fills out data in form input fields, ensuring that the entered values persist even if the user navigates to other pages or logs out of the session can be a challenge. How can we achieve this functionality in vue.js? Despite my attempts, I have no ...

Switch out the view div element with ui-router

Currently, I am utilizing Angular ui-router to manage various views in the following manner: <div ui-view="header"></div> <div ui-view="nav"></div> <div ui-view></div> Upon Angular loading, the divs are automatically p ...

Tips for Sending <Div> Data to a Servlet

I attempted to pass the content of an entire div in a form action URL using JavaScript. However, when I try to retrieve this request parameter as a String on the servlet side, it is returning [object Object]. Below is my code for the form and JavaScript: ...

Performing PHP MySQL table database insertion utilizing the $_GET approach using Codeigniter-3 and Dropzone-4.1 plugin

Currently working with CodeIgniter 3 and running into an issue with "id_case" showing as undefined index. When I click a link in index.php: <?php echo "<td><a href='/ci_dropzone/?id_case=".$row['id_case']."'>Upload File ...

Guide on using PHP to assign the value of an array to an input field

Here is an array I have: $texts = [ "maybank2u.com", "Open BillPayment", "Status: Successful", "Reference number 2950211545", "Transaction date: 01 Feb 2016 13:09:17", "Amount: RM100.00", ...

Adjusting column styles on mobile or desktop devices

My row has two columns <div class="row"> <div class="col-9"> hello </div> <div class="col-3"> world </div> </div> But I want to change the column classes for small screens, so they would be ...