Creating a horizontal scrollbar for multiple rows and columns in Bootstrap: A step-by-step guide

I need a solution where multiple rows and columns can be scrolled horizontally using just one scroll bar. I have already tried implementing the scrollbar for only one row with multiple columns, but it didn't work as expected. Here is the code that I attempted:

.page {
  width: auto;
  margin: auto;
}

.hs {
  list-style: none;
  overflow-x: auto;
  white-space: nowrap;
  width: 100%;
  padding: 0 10% 2rem 0%;
}

.hs .item {
  display: inline-block;
  width: auto;
  text-align: center;
  margin-right: 0.75rem;
  height: 100%;
  white-space: normal;
}

 ::-webkit-scrollbar {
  height: 15px;
}

 ::-webkit-scrollbar-track-piece {
  background-color: gray;
}

.li {
  text-decoration: none;
}
<div class="container page">
  <ul class="hs">
    <li class="item">
      <div class="col-lg-3 col-md-4 col-sm-6 ">
        <div class="card border-0" style="width: 15rem;">
          <img class="card-img-top" src="images/image 25.png" alt="Card image cap">
        </div>
      </div>
    </li>

    <li class="item">
      <div class="col-lg-3 col-md-4 col-sm-6 ">
        <div class="card border-0" style="width: 15rem;">
          <img class="card-img-top" src="images/image 25.png" alt="Card image cap">
        </div>
      </div>
    </li>

    <li class="item">
      <div class="col-lg-3 col-md-4 col-sm-6 ">
        <div class="card border-0" style="width: 15rem;">
          <img class="card-img-top" src="images/image 25.png" alt="Card image cap">
        </div>
      </div>
    </li>
  
   <!-- Additional items shortened for brevity -->

  </ul>

</div>

Answer №1

To ensure proper display, make sure to specify the height and width of your <ul> tag. Adding these attributes will set the dimensions of your list. Additionally, you can style the ul element using overflow-y: scroll; to create a scrollbar effect. If this doesn't work as expected, try using overflow-y: auto; instead.

Here's an example:

ul{
  height: 200px;
  max-height: 200px;
  width: 200px;
  border: 2px solid blue;
  overflow-y: scroll;
}

li{
height: 50px;
border: 2px solid black;
}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width = device-width, initial-scale = 1.0">
        <meta http-equiv="X-UA-Compatible" content = "ie=edge">
        <title> Keat </title>
    </head>

    <body>
        <ul>
          <li>Li-1</li>
          <li>Li-2</li>
          <li>Li-3</li>
          <li>Li-4</li>
          <li>Li-5</li>
          <li>Li-6</li>
        </ul>
    </body>
</html>

Answer №2

To implement a custom scrollbar, follow these steps:

Within a div element, include the following classes:

<div class="custom-scrollbar custom-scrollbar-primary">

Next, in your style tag, add this CSS code:

{

.custom-scrollbar {
 position: relative;
 width: 800px;
 height: 400px;
 overflow: auto;
}

}

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

Require an additional button to dynamically load more content and shift all existing elements further down the page

I am looking to implement a "load more" button for an Instagram feed on my website. My current approach involves increasing the height of a specific section while moving the rest of the page down. This is what I have tried: <script> $(document.ready ...

Encountered an issue while attempting to run the npm run serve command on a

I tried running the following commands to create my first Vue app: vue create myfirstapp atom (for open my editor) cd myfirst app npm run serve But I encountered this error: > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemai ...

What is preventing the Navbar from aligning to the right side in Bootstrap 5?

I'm trying to position only the "Account" navbar all the way on the right side using ms-auto, but it doesn't seem to be working correctly. Here's my code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="u ...

Using functions like nl2br() for new line breaks, preg_replace for replacing patterns, htmlspecialchars() for encoding special

I've reviewed all the answers on this topic, but I'm still struggling to find the correct method for sanitizing data. My task is to enter: <?php echo 'yes'; ?> <?php echo 'yes' ?> into a text area, submit it in ...

Enhancing button functionality using jQuery and JavaScript for toggling behavior

I am facing a challenge with this code. The goal is to have a single script that can handle multiple audio elements on the page and toggle between PLAY and PAUSE buttons by adding or removing classes. Can anyone suggest any changes or additions that coul ...

How can LDAP authentication be implemented in an Angular 8 frontend application?

I need to create a web application with secure content access. I've been advised to implement LDAP authentication on the front-end using Angular. I'm uncertain about its feasibility as I couldn't find relevant information online. Can anyone ...

.css files standing their ground against modifications

Currently, I'm utilizing the WebStorm IDE to work on my React project. My goal is to make modifications to the app.css files in order to update the design. However, each time I attempt to build or run the project, it dismisses all of the changes I&apo ...

Execute HTML code when a button is clicked

I have a piece of HTML code containing all the necessary information about an item for sale on a website, such as title, price, dimensions, and weight. Additionally, it includes an "Add To Cart" button. I have decided to move away from Wix and hand-code m ...

Having trouble getting items to align properly in Bootstrap

As a student, I am struggling with my development skills while attempting to create a personal website. I am encountering difficulty aligning items on my rows in bootstrap. Here is what I am trying to accomplish: 1. However, I am currently stuck at this po ...

What causes a space to appear at the bottom of the screen when elements exceed the height of the screen?

https://i.sstatic.net/jo7W5.png https://i.sstatic.net/Au7OW.png After passing the screen height, I noticed a sudden margin-end appearing. I've tried using '''cover: 100% 100''', but the image ends up shrinking. As my fr ...

Using Javascript to replace elements with input fields and text areas

I'm currently working on a unique project for my Wordpress blog, where I am developing a custom block editor using JavaScript on the frontend. The goal is to convert all elements from the post content into a series of inputs and textareas. To begin, ...

Position the vertical bar directly adjacent to the form input field

Looking for assistance with creating a unique webpage layout that includes a form where the employee ID is visually separated from the rest of the content by a vertical bar extending across the entire page. However, my attempts to achieve this using a gr ...

Encountered an error while attempting to load resource: the server returned a 404 (Not Found) status code when trying to load an image in an

I am looking to dynamically load an image when it is selected from a file picker dialog. The code provided below attempts to achieve this, however, the image does not load into the img tag. <script src="https://cdnjs.cloudflare.com/ajax/libs/jq ...

Generating nested arrays using Vue.js

Calculating the total costs of products selected by a user for each company is my current task. Below is the code snippet I am using: let companiesProductPrices = []; let prices = []; this.selectedCompaniesDetails.forEach ...

Creating responsive images with Bootstrap 5

1 I am currently using Bootstrap 5 to develop a website and encountering an issue with getting images to move above text in the feature and mission sections on mobile or tablet screens. Previously, I was able to achieve this effect using the following cod ...

Transforming a Java Array or Collection into a JSON array

After running my Java code, the returned Collection (ArrayList) produces JSON through JAXB that looks like: {"todo":[{"name":"CAMPBELL","sales":"3","time":"1331662363931"}, {"name":"FRESNO","sales":"2","time":"1331662363931"}]} However, I am wondering if ...

Animation of CSS height when image/icon is hovered over

Having an issue with my icon when hovering. I am trying to change the img src on hover. Here is the code I currently have: #aks { width: 0px; max-height: 0; transition: max-height 0.15s ease-out; overflow: hidden; background: url("https://img. ...

Issues with Angular's *ngIf directive not functioning correctly

Within my template, I have a block of HTML that controls the visibility of a div. <div *ngIf="csvVisible"> <p>Paragraph works</p> </div> This particular code snippet belongs to my component. export class SettingsComponent imple ...

Color scheme for navigation bar carousel item background color

I have a navigation bar and carousel within the same section. I want to change the background color of both the navigation bar and carousel item when the carousel indicator becomes active. Any suggestions on how to achieve this using a jQuery function? H ...

Designing an accordion with the main content peeking out slightly before collapsing into place

Seeking assistance in creating an accordion that displays a snippet of content before collapsing. I'm facing difficulty starting this project. While a basic accordion is simple to implement, I am unsure how to show a portion of the content (such as t ...