Responsive tables in Bootstrap 4 that are nested

I am currently utilizing Bootstrap 4. I have a complex table structure where I want only the second column and onward to be scrollable. The challenge is making this specific part of the table responsive while keeping the rest static. I attempted to nest a table within a table, with everything from the second column onwards wrapped in a table-response div. Unfortunately, this approach did not achieve the desired responsiveness. It seems that the entire table needs to be marked as responsive for it to work correctly.

My goal is to create a scrollable table, with the ID wannabe-responsive, that maintains its responsiveness, while the first table with the ID not-responsive remains fixed. I have tried various CSS adjustments without success. Here is the current code structure:

.item {
  min-height: 350px;
  border: 1px solid #000;
  margin-bottom: 20px;
  background: #f2f2f2
}

In the code snippet above, you can see my attempt to style the table content. I have included a link to a JS Fiddle to demonstrate my progress so far. While I have made some improvements, I am still facing issues with the table content overflowing the container. I will continue to update as I make further advancements.

Update: Adding the container class to the <td> container of the response table has improved the responsiveness. However, I am still struggling with data overflowing outside the main container. I am actively working on resolving this issue and will provide updates.

Update 2: Feel free to review my progress on the JS Fiddle link. I have almost achieved the desired functionality, but I am encountering difficulty with the content being cut off at the end. When you run the fiddle, you will notice that the time slots are truncated, along with the end of the scroll bar on small screens. My objective is to ensure that the entire scroll bar is visible at the bottom at all times, and that all time slots are fully viewable while scrolling.

Current display: https://i.sstatic.net/FWCr9.png

As shown in the image, both the end time slots and the scroll bar are being cut off. I appreciate any assistance in overcoming this final hurdle!

Answer №1

In my opinion, nesting too many tables is not ideal as it can be challenging to manage responsive design. To address this, I replaced the left table with flex and eliminated the outer table. The following code snippet demonstrates the fix:

<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">

<style type="text/css">
.item {
min-height: 350px;
border: 1px solid #000;
margin-bottom: 20px;
background: #f2f2f2
}

.names {
padding: 50px 0 34px;
}

.names > div {
border: 1px solid #dee2e6;
flex: 1;
display: flex;
align-items: center;
justify-content: center;
padding: 10px;
height: 50px;
}

.table td {
height: 50px;
}
</style>
</head>
<body>

<div class="container-fluid">
<div class="item mx-5 mt-2" style="overflow: hidden">
<h2 class="p-2 bg-primary text-white">Inventory</h2>
<div class="text-center">
<h3 style="border-bottom: 1px solid #000">Time Chart</h3>
</div>

<div class="d-flex p-4">
<div class="d-flex flex-column justify-content-between names pr-2">
<div>Potatoes</div>
<div>Apples</div>    
<div>Corn</div>
<div>Lettuce</div>
</div>

<div class="table-responsive">
<table class="table table-bordered text-center">
<thead>
<th>1:20</th>
<th>1:52</th>
<th>2:30</th>
<th>3:17</th>
<th>3:35</th>
<th>4:22</th>
<th>4:45</th>
<th>5:15</th>
<th>6:15</th>
<th>6:30</th>
<th>7:25</th>
<th>7:37</th>
<th>7:50</th>
<th>8:02</th>
<th>8:15</th>
<th>8:27</th>
<th>8:40</th>
<th>8:52</th>
</thead>
<tbody>
<tr>
<td>1</td>
...
...
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
</body>
</html>

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

Incorporating a variety of images into this hexagonal design framework

Hello there! I am just starting to learn CSS and HTML, and I have a question. Is it possible for me to use the same CSS styling but have different images inside each of the hexagons? I want to replace the image '' with multiple images without rep ...

How can I prevent scrolling in a Vue mobile menu?

In this scenario, the toggle for the menu is controlled by a checkbox with the id "check" below. I attempted to bind v-bind:class="[{'antiscroll': checkboxValue}]" to the body in HTML, and also in the main App.vue file, but it did not work as exp ...

Creating a Click Counter with jQuery 2.0.1/2.0.2: A Step-by-Step Guide

Currently in the process of creating a fundraising webpage for charity, I have chosen to display an animated rabbit making its way Around The World. My progress so far includes a non-looping gif that plays on click, with a limitation on how often it can b ...

Issue with overflow:scroll displaying incomplete div contents

I am attempting to create a sidebar with a fixed position, featuring a small header and a scrollable content area below it. The issue I am facing is that I am unable to scroll through the entire content within the div, resulting in some parts being cut of ...

What is the significance of the space between form.validate and .ng-invalid-email.ng-dirty?

I'm currently working on an AngularJS application and I'm confused about the spacing between "form.validate" and ".ng-invalid-email.ng-dirty" in the stylesheet code below: <style> form.validate .ng-invalid-required.ng-dirty {background ...

Incorporate props within the CSS template string of Emotion for enhanced styling flexibility

I am currently in the process of transitioning my design system from styled-components to emotion. Within styled-components, the following syntax is considered valid: export interface AvatarProps { // ... shape: AvatarShape; size: AvatarSize; } con ...

Placing text beside an image

I am brand new to osCommerce and recently took over this code. We are looking to improve the layout of the new_products page. Here is the current display code: div class="contentText"> <div class="NewProductsList"> <table border="0 ...

Overflow: Truncating text with an ellipsis in the center

Seeking a CSS-only solution for adding an ellipsis in the middle of a string when it exceeds its container. I have tried splitting the container in half, trimming the first half with a wrapper on a whole letter and adding an ellipsis to the front of the s ...

Issue with event listener arising once elements have been loaded into the dom

I have a project where I want to click on a category card to obtain its id and then redirect to the movies screen. I understand that using row.eventlistener() in index.js executes before the elements are rendered, causing the id not to be captured. How ca ...

`The Best Times to Utilize Various Image Formats Within a Single Webpage`

If I have two identical images displayed on a page at different sizes, what is the best option for optimizing performance? On one hand, using an image already sized correctly can improve performance, especially on mobile devices. On the other hand, using t ...

Accessing a key from an AJAX JSON response and applying it within a .each() loop in jQuery

I'm struggling with a seemingly simple task that I just can't seem to get right. My goal is to convert multiple text inputs into select fields using AJAX and jQuery. Everything works smoothly, except when trying to make the $.each function dynam ...

Creating a color-changing checkbox toggle in Bootstrap 5

Is it possible to customize the color of a Bootstrap 5 switch without changing it site-wide? I want some checkbox switches to have a unique color. Most tutorials online only cover how to change colors globally or use images, but I'm hoping to achieve ...

How can I construct a frame-like structure using PHP and HTML?

Looking to create a page with a two-frame structure. The left frame will always display a small form with 10 entries that, upon submission, trigger some processing and display results. The left frame must remain accessible at all times, while the right fra ...

Hiding a related field using a designated delimiter can be achieved with JavaScript

I am looking to create a function that hides the corresponding textarea field of a dropdown. This functionality will be utilized in multiple instances, hence the need for it to be within a function. <div id="formElement1" class="field"> <labe ...

Preserve the height of the previous div following an AJAX request

I am currently facing an issue where I have a script that utilizes ajax to receive a response containing a cart string (html code) with items from the cart. Inside the response handler, there is another script that sets the height of each div in the cart s ...

The entire space on an HTML page should be occupied with content from the header to the footer

I am currently implementing jQuery Mobile on my project. The page I have created consists of a fixed header and footer with only two buttons. Due to the fixed footer, half of the page is in silver color (data-theme=c) while the bottom half is gray. My goa ...

The functionality of Skrollr on mobile is currently not working properly due to the inability to prevent default actions

Encountering the following error on all chromium browsers while using the Skrollr library and accessing the website through mobile: "[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See < ...

The issue with Angular-gettext is that it fails to update dynamically generated strings in the code

Whenever I try to set the language using the code gettextCatalog.setCurrentLanguage(langString);, it doesn't seem to affect my side-nav menu. My side menu has two possible states: expanded or collapsed, and I use ng-include to control its content base ...

The jQuery focus event appears to be malfunctioning

I am attempting to utilize the jQuery focus event to handle the following situation: There are three search criteria options: Post code, city, radius. The user can only select one option, indicated by a radio button. The requirement is that when a user c ...

Eliminate spacing between divs of varying heights

I'm facing an issue with my small gallery of images. Despite having the same width, they vary in height causing the second row to start below the tallest image from the previous row. How can I eliminate these empty spaces while still maintaining the v ...