Data tables that are able to scroll horizontally without the need for any framework and

Seeking a responsive table solution similar to Bootstrap, but without using Bootstrap's Javascript and CSS due to the website being built from scratch with no frameworks. Check out this demo: http://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_ref_table-responsive&stacked=h

Wondering if there is a straightforward solution to achieve this effect using just CSS and basic Javascript, or maybe a jQuery plugin? Explored different options but haven't found one that simply adds a vertical scroll bar.

Answer №1

Here's everything you require:

.yourTableClass {
  display: block;
  overflow-x: auto;
}

Check it out:

table {
  display: block;
  overflow-x: auto;
}


/* The following rules are unnecessary! */
table {
  margin: 0 1rem;
}
td {
  white-space: nowrap;
  padding: 3px 8px;
}
<table>
  <tr>
    <th> 1 </th>
    <th> 2 </th>
    <th> 3 </th>
    <th> 4 </th>
    <th> 5 </th>
    <th> 6 </th>
    <th> 7 </th>
    <th> 8 </th>
    <th> 9 </th>
    <th> 10 </th>
  </tr>
  <tr>
    <td> first column</td>
    <td> second column</td>
    <td> third column</td>
    <td> fourth column</td>
    <td> fifth column</td>
    <td> sixth column</td>
    <td> seventh column</td>
    <td> eighth column</td>
    <td> nineth column</td>
    <td> tenth column</td>
  </tr>
</table>

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

Altering the "src" property of the <script> tag

Can the "src" attribute of a current <script> element be altered using Jquery.attr()? I believed it would be an easy method to enable JSONP functionality, however, I am encountering difficulties in making it operate effectively. ...

Encountering an unexplained JSON error while working with JavaScript

I'm trying to retrieve data from a JSON API server using JavaScript AJAX and display it in an HTML table. However, I keep encountering an undefined error with the data displaying like this: Name id undefined undefined This is my code snippe ...

Using jQuery to target a specific item from a retrieved list of elements

I'm currently working on a photo gallery feature that is reminiscent of Instagram or Facebook user photos. My goal is to enable users to view details about each image (such as the date) in a box that appears over the image when they hover over it. E ...

The One-time-password (OTP) page fails to display following the successful transmission of the OTP to the user through PHP

I've hit a bump in my class project and could use some help. Currently, I'm working on a login form that requires users to enter a one-time password sent to their email for authorization. Successfully, the one-time password (OTP) and the curren ...

Switching classes on the currently active tab

I have implemented Angular UI tabs with buttons that switch to different tabs. I am attempting to change the style of a button when its corresponding tab is active by using ng-class to dynamically apply styles. Inside my scope, I have a function that retu ...

Is there a way to modify an Amplify SignUp Attribute module?

Struggling with formatting required attributes for a user signup in Amplify/Cognito. I tried following the instructions on adding a custom 'gender' field after the default form fields, but it's not syncing up with Cognito. Although I manage ...

Determine the optimal width for each element based on the total number of instances of that element present

If there is an unknown quantity of elements, could they be expanded in the following manner: 1 element: [========] 2 elements: [===][===] 3 elements: [===][===] [========] 4 elements: [===][===] [===][===] The [===]'s represent elements. To add ...

Struggling with displaying a CSS dropdown menu below its parent element?

I need help with my menu structure. <nav id="nav"> <ul> <li>Home</li> <li>Menu1 <ul> <li>Sub1</li> <li>Sub2</li> </ul> </li> <li>Menu2 <ul> & ...

Would it be frowned upon to select unique elements by referencing their class or ID through a string?

After utilizing jQuery for quite some time, I am curious about best and worst practices. Let's examine this piece of HTML: <span class="а_s_trigger" id="tekst1">text1</span> <span class="а_s_trigger" id="video1">video1</span&g ...

Identifying Instances of Classes with the Identical Name Using Selenium

I'm currently working on tallying up each instance of the class named product unlocked enabled. I have it set to automatically recount at intervals, increasing the count as more classes change their name. Despite conducting extensive research online, ...

Determining the number of columns and rows within an HTML table

Is there a way to determine the number of columns and rows in an HTML file? How can we accurately count the total number of td tags present within the HTML file? ...

Struggling to implement a vertical scroll bar in HTML code?

<body ng-app="myApp" ng-controller="myCtrl"> <div ng-show = "dataFromRest" ng-repeat = "x in dataFromRest.posts" > <div class="tittle" style="width: 25%;"> <a href="" ng-click="showDi ...

I'm having trouble getting the footer to stay at the bottom of the window instead of the page. Any tips on

I've exhausted all resources searching for a solution to my issue, but nothing seems to quite fit. The floats on my page are extending beyond the boundaries, and when I load in the footer, it stubbornly sits at the bottom of the initial viewport befor ...

Displaying a header on each page along with a gridview that has authentic pagination

I'm struggling with setting up my header div and grid view to print correctly across multiple pages. The header div looks like this: <div id="header" style="width:100%; padding: 6px; margin-right: 20px; border-top-style: dotted; border-color: inh ...

An error occurred due to an invalid model value being used in a foreach loop

Within my table, I have a list of Roles displayed in three columns: Name, Edit, and Delete. Clicking on the Edit button directs users to a form where they can modify the role's name. Selecting Delete triggers a modal dialog for confirmation prior to d ...

Issue with Bootstrap 5 collapse not toggling back on second button press

I am encountering an issue with a button that is supposed to show a div on click using Bootstrap 5's "Collapse" class. The problem is that the content shows up correctly on the first click, but it doesn't hide again when the user clicks the butto ...

The href attribute in a stylesheet link node is malfunctioning

When setting up my website, I experimented with two different methods. 1) The first method involved using node to run the server. 2) The second method simply used an index.html file on my local computer. Interestingly, I noticed a difference in how the s ...

Jquery function for determining height across multiple browsers

I am currently facing an issue with setting the height of table cells in my project. While everything works smoothly on most browsers, Firefox seems to add borders to the overall height which is causing inconsistency across different browsers. If anyone k ...

When the browser width is reduced, the text appears outside of the image

When pasting text into an image in this example, everything looks fine at first. However, as the browser width is reduced, the text starts slipping out of the picture. To make matters worse, unsightly line breaks are also added. Is there a way to prevent ...

Using jQuery, how can I dynamically change the stacking order of an element when clicked?

I'm struggling to change the z-Index on button click. I have a static image and a dynamic div, and I want to send the #imgDiv1 behind the static image. Unfortunately, despite trying everything, I haven't been able to achieve this. You can check ...