Horizontal scrolling of columns using tabs

My website features a row of tabs, however, as the number of tabs increases, the "Knowledgebase" tab gets pushed to the bottom and triggers a vertical scrollbar. I'm looking for a way to implement horizontal scrolling for the tab row so that all the tabs are always visible, and the "Knowledgebase" tab remains in its original position.

I attempted using overflow: scroll in the CSS, but it didn't yield the desired results. How can I achieve horizontal scrolling when necessary to keep all tabs visible and prevent the "Knowledgebase" tab from being pushed down?

To view the website layout, visit https://i.sstatic.net/NeZRC.png

Here's a snippet of the code:

<div class="col-lg-3">
        <div data-spy="scroll" data-offset="0" tabindex="0" style="height: 100%; overflow-y: scroll; position: relative;">
            <div class="tab-content border">
                <ul class="nav nav-tabs" id="myTab" role="tablist">
                    <li class="nav-item" role="presentation">
                        <button class="nav-link active" id="tab-ticket" data-bs-toggle="tab" data-bs-target="#ticket" type="button" role="tab" aria-controls="ticket" aria-selected="true">Ticket</button>
                    </li>
                    <li class="nav-item" role="presentation">
                        <button class="nav-link" id="contact-tab" data-bs-toggle="tab" data-bs-target="#contact" type="button" role="tab" aria-controls="contact" aria-selected="false">Customer</button>
                    </li>
                    <li class="nav-item" role="presentation">
                        <button class="nav-link" id="knowledge-tab" data-bs-toggle="tab" data-bs-target="#knowledge" type="button" role="tab" aria-controls="knowledge" aria-selected="false">Knowledge</button>
                    </li>
                </ul>
                <div class="tab-content" id="myTabContent">
                    ...
                </div>
            </div>
        </div>
    </div>

Answer №1

I've implemented a solution using 'nowrap' to prevent overflow. Another option is setting a fixed width, which should also work for you.

#myTab{
overflow-x:auto;
flex-wrap:nowrap;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f2909d9d868186809382b2c7dcc2dcc0">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
 <ul class="nav nav-tabs" id="myTab" role="tablist">
                            <li class="nav-item" role="presentation">
                                <button class="nav-link active" id="tab-ticket" data-bs-toggle="tab" data-bs-target="#ticket" type="button" role="tab" aria-controls="ticket" aria-selected="true">Ticket</button>
                            </li>
                            <li class="nav-item" role="presentation">
                                <button class="nav-link" id="contact-tab" data-bs-toggle="tab" data-bs-target="#contact" type="button" role="tab" aria-controls="contact" aria-selected="false">Customer</button>
                            </li>
                            <li class="nav-item" role="presentation">
                                <button class="nav-link" id="knowledge-tab" data-bs-toggle="tab" data-bs-target="#knowledge" type="button" role="tab" aria-controls="knowledge" aria-selected="false">Knowledge</button>
                            </li>
                             <!-- Repeat this line as needed -->
                        </ul>

Answer №2

If you want the row of tabs to scroll horizontally when there are numerous tabs, you can implement the following CSS modifications:

  1. Eliminate the data-spy="scroll" attribute and inline style with overflow-y: scroll from the tab list container (
    <div class="col-lg-3">
    );
  2. Add a new CSS class to the tab list container to manage horizontal scrolling behavior (for instance, tab-list-container);
  3. Apply the required CSS styles to facilitate horizontal scrolling and guarantee all tabs remain visible.

Check out the modified HTML and CSS code below:

<div class="col-lg-3">
 <div class="tab-list-container">
  <div class="tab-content border">
   <!-- Tab content and other elements -->
  </div>
 </div>
</div>
    
.tab-list-container {
  overflow-x: auto;
  white-space: nowrap;
  width: 100%;
}
    
/* Optional */
.tab-list-container .tab-content {
  padding-right: 15px;
}
    
/* Optional */
.tab-list-container::-webkit-scrollbar {
  width: 8px;
}
    
.tab-list-container::-webkit-scrollbar-thumb {
  background-color: #888;
  border-radius: 4px;
}

After making these adjustments, the tab row will now scroll horizontally as needed, ensuring visibility of all tabs, including the "Knowledgebase" tab. The tab-list-container class enables horizontal scrolling by using overflow-x: auto, while white-space: nowrap ensures tabs are displayed in a single line. The optional CSS styles for the scrollbar allow for visual customization based on your preferences.

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

Position of fixed div set relative to its parent fixed div

I'm facing an unusual situation where I need a fixed div to be positioned relative to its parent, which is also a fixed div. When you take a look at my example, everything will become clear. <div class="drawer"> <p>Drawer</p> & ...

What makes @font-face function on Safari but not on Firefox in Mac versions?

Can anyone help me troubleshoot a font issue on my website? I've added the following code to the CSS file, and it's working fine in Safari, but not in Firefox. I'm new to coding, so please bear with me if this seems like a basic question. I& ...

Grid item overlay

Currently, I am facing an issue with React where I am attempting to place an overlay on top of each grid item in a grid. Despite trying multiple approaches, the overlay appears beneath each grid item instead of over it. Even setting the position: absolute ...

When you tap on the child element, ignore the parent element

Is there a way to make CSS understand that clicking on a child element within the parent should not be considered as clicking on the parent as well? Why not give it a try by clicking on one of the children inside the parent? .parent{ background: b ...

Is there a way to keep my footer fixed to the bottom of the page in Google Chrome?

I recently made some updates to my aging website by adding a footer menu. However, I encountered an issue with the placement of the footer on Google Chrome. It appears too high, overlapping certain elements of the site. I attempted to resolve this problem ...

What is the best way to display an alert when the button is clicked repeatedly?

Is it possible to keep displaying the alert every time we click the button, rather than just once after clicking it? I currently have an alert set to trigger when a button is clicked, but it disappears after 3 seconds. How can I make it show up again with ...

Interested in learning how to filter nested tables?

After successfully integrating a filter code snippet, I encountered an issue with the filter not recognizing data tables that can only be inserted as nested tables. Due to my limited knowledge of JavaScript/CSS, I'm unsure if this problem can be resol ...

Is it possible for the HTML (source code of a web page) to alter once the page is saved onto a local computer?

Upon opening a webpage at http://www.designova.net/rise/index-01.html, I decided to inspect its source code. Afterwards, I saved the page to my computer and opened it in an editor (sublime text 2). To my surprise, I noticed that the HTML content in the two ...

Retrieve the HTML content of all children except for a specific child element in jQuery

Is there a way to utilize jQuery/Javascript for selecting the HTML content of the two <p> elements in the initial <div class="description? I'm open to using Regex as well. This specific jQuery selection is being executed within Node.js on a c ...

"Struggling to divide CSS Code with PHP containing nested brackets? Here's how you can tackle it

I'm currently attempting to break down my CSS code stored in variables, but I consistently encounter issues when dealing with media queries or similar elements. While I don't require every single rule to be outlined, I am looking for a solution ...

Prevent the content within a Card from spilling over its borders

I am currently utilizing the grid system to organize three filters and a button. The button is slightly overlapping outside of the card, and I would like it to automatically move to a new row if it doesn't fit within the current layout. Despite exper ...

Is it possible to customize the bullet color for an unordered list using li:before?

Recently, I came across a clever solution for changing the color of a bullet point. The method mentioned an alternative approach as well. "If you're unable to edit your HTML, you can opt for list-style-image with a customized colored dot, or utilize ...

Having difficulty modifying the styling of a paragraph within a div container

I have been working on a function that is supposed to adjust the font-size and text-align properties of a paragraph located within a div tag once a button is pressed. function customizeText() { document.getElementById('centretext').innerHTML = ...

What is the best way to open an HTML file with Python without restrictions?

My HTML file is quite large, containing 4,574 words and 57,718 characters. However, when I try to read it using the .read() command, it only displays 3,004 words and 39,248 characters when I export it. Is there a way to read and export it without any lim ...

What could be causing this issue with the jQuery CSS not functioning properly?

When I come across the following HTML snippet: <div id="map"> <div class="elem"> hey1 </div> <div class="elem"> hey2 </div> <div class="elem"> hey3 </div> </div> In JavaScript: va ...

Unable to retrieve the unprocessed value (including periods) from an HTML number input

Whenever I press a key on the <input type="number" id="n" /> and then type a ., it appears in the input but does not show up in $('#n').val(). For instance, if I type 123., the result from $('#n').val() is just 123. Is there a w ...

Changing text color with JQuery animation

Is there a way to animate text color using jQuery/jQuery UI? I want the text color to change from #000 to #F00 when an event is triggered, then fade back to #000 over 3 seconds. I attempted using effect("highlight", {}, 3000) with the highlight effect, bu ...

Separating buttons (two buttons switching on and off simultaneously) and displaying the corresponding button based on the data

My current project involves creating a registration page for specific courses. While I am able to display the information correctly, I am facing an issue with the ng-repeat function. The problem lies in all the Register buttons toggling incorrectly. Additi ...

There seems to be a problem with displaying two div elements side by side using Html/CSS

Recently, I've delved into the world of html/css/javascript just for fun. I've encountered a little roadblock and I could use some help. In my html code, I'm trying to display two div elements on the same line but for some reason, it's ...

Tips for generating an input element using JavaScript without the need for it to have the ":valid" attribute for styling with CSS

My simple input in HTML/CSS works perfectly, but when I tried to automate the process by writing a JavaScript function to create multiple inputs, I encountered an issue. The input created with JavaScript is already considered valid (from a CSS ":valid" sta ...