Tips for creating responsive scrollable columns in an HTML table with Bootstrap

I'm not a professional web designer. I attempted to create a web layout with scrollable columns containing data in anchor tags that are loaded dynamically. To achieve this, I created an HTML table structure along with a stylesheet. Here is the source code for the table:

<table>
        <tr>
            <!--COLUMN HEADERS -->
            <td id="titles" style="width: 50%">
                <b style="padding-left: 4%">CURRENCY</b>
                <b style="padding-left: 9%">COUNTRY</b> 
                <b style="padding-left: 8%">SECTOR</b> 
                <b style="padding-left: 4%">LOCATION COUNT</b>
            </td>
        </tr>
        <tr>
            <td style="width: 50%">
                <div id="column">
                    <div ng-repeat="currency in allCurrencies">
                        <a href=""
                            ng-click="filterProductByCurrency(currency); filterCountryByCurrency(currency); filterSectorByCurrency(currency)">
                            <span ng-bind="currency"></span> <br>
                        </a> 
                        <input type="hidden" name="currencyHolder" ng-model="selCurrency">
                    </div>
                </div>
                <div id="column">
                    <div ng-repeat="country in allCountries">
                        <a href=""
                            ng-click="filterProductByCountry(country); filterSectorByCurrAndCtry(country)">
                            <span ng-bind="country"></span> <br>
                        </a> 
                        <input type="hidden" name="countryHolder" ng-model="selCountry">
                    </div>
                </div>
                <div id="column">
                    <div ng-repeat="sector in allSectors">
                        <a href="" ng-click="filterProductBySectors(sector); filterLocBySectors(sector)"> <span
                            ng-bind="sector"></span> <br>
                        </a> 
                        <input type="hidden" name="variantHolder" ng-model="selVariant">
                    </div>
                </div>
                <div id="column">
                    <div ng-repeat="locCount in locationRangeValues">
                        <a href="" ng-click="filterProductByRange(locCount)"> 
                        <span ng-bind="locCount"></span> <br>
                        </a>
                    </div>
                </div>
            </td>
        </tr>
</table>

The CSS styling for the column class is as follows:

#column {
    background-color: #f5f5f5;
    float: left;
    width: 14%;
    height: 125px;
    overflow: auto;
    overflow-y: scroll;
    white-space: nowrap;
    text-align: center;
}

For the titles class, the CSS styling is:

#titles{
    background-color: #f5f5f5;
    color: #069; 
    fill: #069;
}

Although this setup works well, it lacks responsiveness. I have integrated Bootstrap into my application. Is there a way to make this layout more responsive using Bootstrap? Any assistance would be greatly appreciated.

Answer №1

To ensure your table is responsive, simply enclose it within a <div> tag and add the class .table-responsive, as illustrated below:

<div class="table-responsive"> 
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>Row</th>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Email</th>
                <th>Biography</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>1</td>
                <td>John</td>
                <td>Carter</td>
                <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f79d989f99949685839285b79a969e9bd994989a">[email protected]</a></td>
                <td>Lorem ipsum dolor sit amet…</td>
            </tr>
            <tr>
                <td>2</td>
                <td>Peter</td>
                <td>Parker</td>
                <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7606130213040617041d1304361b171f1a5815191b">[email protected]</a></td>
                <td>Vestibulum consectetur scelerisque…</td>
            </tr>
            <tr>
                <td>3</td>
                <td>John</td>
                <td>Rambo</td>
                <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee848186809c8f838c81ae838f8782c08d8183">[email protected]</a></td>
                <td>Integer pulvinar leo id risus…</td>
            </tr>
        </tbody>
    </table>
</div>

Check out a live demo here

Answer №2

Explore this sample with bootstrap headers and a responsive class added to the div elements

<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Table</h2>
  <p>The .table-responsive class creates a responsive table which will scroll horizontally on small devices (under 768px). When viewing on anything larger than 768px wide, there is no difference:</p>
  <div class="table-responsive">
  <table class="table">
    <thead>
      <tr>
        <th>#</th>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Age</th>
        <th>City</th>
        <th>Country</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1</td>
        <td>Anna</td>
        <td>Pitt</td>
        <td>35</td>
        <td>New York</td>
        <td>USA</td>
      </tr>
    </tbody>
  </table>
  </div>
</div>

</body>
</html>

Answer №3

To convert the td elements to div using a combination of jQuery and css, it is possible but not straightforward. It would require writing specific css for each individual table in your application. For more information on this technique, you can visit this link.

If you prefer not to write custom css, you can follow RAHUL's recommendation for creating scrollable tables for smaller screens using bootstrap.

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 AngularJS integrated with Spring MVC is failing to render the desired page

Hello everyone, I'm fairly new to AngularJS and Spring MVC. I've managed to set up a basic application, but unfortunately, when I try to load it, nothing appears on the screen. The console shows a 404 error. I've double-checked everything, b ...

Steps for designing an HTML table that expands and collapses partially

I am currently revamping an old "Top Screens" page by expanding the display from the top 30 to the top 100 in a basic html table format. However, I only want to show the top 20 on page load with an expand/collapse feature. While I have come across examples ...

Steps for accessing the `<img>` tag within an `<a>` tag to focus on the `<img>` element in Internet Explorer

How can I target the img tag inside an href tag to set focus on the <img> element? For example: <a href="#"><img class="img1" src="abc.png"/></a> The CSS selector a .img1:focus {} does not seem to work. I am unable to access the ...

I require assistance in troubleshooting and repairing my HTML and JavaScript code

I am working on creating a feature where users can input their upcoming birthday date and receive an alert showing how many days are left until then. However, I encountered an issue where the alert displays NaN (Not a Number) before the birthday is entered ...

Resolving VSCode WebViewPanel access issues through a corporate proxy

I am currently utilizing the "C4 DSL Extension" in VSCode to display previews of my architecture diagrams. These previews are generated through the WebviewPanel functionality. If you're interested, you can access the source code here: While everythin ...

How come the mouseover effect on the div remains even after the mouse has been removed?

How can I keep the original CSS class when the mouse moves away? function highlight( x, y) { var sel=document.getElementById(y); sel.style.borderBottom= "2px solid "+x; sel.style.opacity="1"; sel.style.transition="all eas ...

In production mode, the Angular/JS Express app is stuck in an endless routing loop, while it functions perfectly in development mode

My webapp is constructed using generator-angular-fullstack. While it functions properly in development mode (grunt serve), I encounter a problem with what appears to be an endless routing loop when switching to production mode (grunt serve:dist). The outp ...

What is the best way to swap out an HTML file with another without altering the link?

I'm working on an HTML file, which is basically a webpage. My goal is to create a functionality where clicking a button will dynamically replace the content of the page with another HTML file, complete with its own CSS, JavaScript functions, and other ...

Tips on toggling the visibility of div elements with JavaScript

In my selection block, I have three categories of elements and associated Divs. The goal is to display the related divs when a category is selected, while keeping them hidden otherwise. Specifically, I want the husband_name and number_pregnancy divs to be ...

Analyzing HTML content (not properly formatted) using JSoup

When attempting to parse an HTML page using Jsoup, I encountered some unusual issues. The problematic page is located at , and it is not well-formed. This could potentially impact the parsing process. According to Chrome: /html/body/table[2]/tbody/tr/t ...

Retrieving the HTML Head Element from Internet Explorer's Document Object Model

For extracting the HTML body of a document, I am familiar with utilizing the IHTMLDocument2 interface by invoking the get_body member function. However, obtaining the head seems to be more challenging. Is there an alternative method since the IHTMLDocumen ...

"Obtain a DOM element within an Angular directive by using the jQuery find method

When inspecting the DOM, I can see the element anchor tag present but cannot retrieve it using jquery.find(). The console returns a length of 0, preventing me from initializing angular xeditable on that element. angular.module('built.objects') ...

Top approach for inserting Class instance into a group

I need some guidance on how to approach this issue. I am interested in creating a set of objects similar to the example below: Person P = new Person(); P.Name = 'John'; P.Surname = 'Dough'; var People = []; People.push(P); Can this b ...

Transfer information from .gs (Google Apps Script) to a variable inside a <script> tag in an HTML document

[ {"id":1,"label":"Node 2"}, {"id":2,"label":"Node 3"}, {"id":3,"label":"Node 4"}, {"id":4,"label":"Node 5"} ] Hello there! The function getArray() in the code snippet above is returning the specified string ↑. I need help connecting this data w ...

What can I do to adjust the position of the div wrapper if the floating sidebar is taller than

Check out this example http://jsfiddle.net/NuzDj/ When you resize the window, the sidebar overlaps with the wrapper and footer. Is there a way to automatically adjust the height of the wrapper when the sidebar overlaps with it? ...

Selecting JavaScript file on change as default option

Currently, I have an HTML file that prompts the user to select an XML file when the file selection is changed. Is there a way to make it so that by default, only one file is chosen? <form id='fileSelection' action=""> <center> <in ...

Troubleshooting ASP.NET Content Page Error: jQuery Object Expected

Currently working on designing a personal ASP.NET Web page, I have encountered an issue with making a sticky div using jQuery. Despite all my other jQuery functions functioning properly, the sticky div seems to be causing trouble. stickydiv.js $(document ...

Increased space between the sidebar and the top bar

Currently, my code is a bit messy as I am still in the learning stages of bootstrap. I need some assistance on how to resolve the empty space that exists between the top and side bar elements. <!DOCTYPE html> <html lang="en"> <sty ...

Optimizing website layout for mobile devices

I have a website with a fixed page layout at . It displays properly on desktop browsers but not on mobile devices. The website is adjusting to fit the browser size, but some components are changing format. Can anyone offer assistance? Thank you! ...

I am facing an issue where the controller cannot be located within the required attribute of my directive

Here is the HTML code snippet I am working with: <nav> <ul rf-hover-wrapper> <li rf-hover-child rf-on-hover-class="hover">Home</li> <li rf-hover-child rf-on-hover-class="hover">About us</li> <li rf-hove ...