Hide additional tabs on the page when the width of the tabs exceeds the page width

I am currently working on a Google module tab application. I have successfully added the tab control with drag and drop functionality within a specific area. However, I now need to limit the number of tabs displayed on the page. Regardless of the total count of tabs, if they exceed the size of the page, I want the extra tabs to be hidden. How can I implement this feature?

Attached below is a snapshot of my project output where tabs 8 and 9 are appearing on a separate line instead of staying in line with the rest of the tabs. I am looking for solutions to ensure that all tabs remain on the same line. Any suggestions or advice would be greatly appreciated.

To provide more context, here is a visual representation of the issue:

The goal is to keep all tabs on the same line regardless of the window size. If the window is too small to accommodate all tabs, the additional tabs should be hidden. Conversely, if the window is large enough, all tabs should be visible to the user.

The HTML code for the buttons representing each tab is as follows:

<div class="limit">
    <button data-tab="tab-1" class="button current">Car 1</button>
    <button data-tab="tab-2" class="button">Car 2</button>
    <button data-tab="tab-3" class="button">Car 3</button>
    <button data-tab="tab-4" class="button">Car 4</button>
    <button data-tab="tab-5" class="button">Car 5</button>
    <button data-tab="tab-6" class="button">Computer</button>
    <button data-tab="tab-7" class="button">Message</button>
    <button data-tab="tab-8" class="button">Nature</button>
    <button data-tab="tab-9" class="button">Power</button>
</div>

In terms of styling, I have defined CSS properties for both the parent container and button elements:

.parent {
    position: relative;
    margin: 20px;
    width: 800px;
    height: 40px;
}
.button {
    position: relative;
    left: 0;
    display: inline;
    width: 200px;
    height: 75px;
    background-color: lightgray;
    font-size: large;
    border-radius: 4px;
    border: 1px solid #ccc;
    margin: 0 10px 0;
    box-shadow: 0 0 2px #fff inset;
    -webkit-transform: perspective(100px) rotateX(30deg);
    -o-transform: rotateX(30deg);
    -ms-transform: rotateX(30deg);
    -moz-transform: perspective(100px) rotateX(30deg);
}

Answer №1

Here is a solution for you:

Check out the jsfiddle and try dragging the output. It functions exactly as you need it to.

.limit {
 overflow:hidden;
  height:75px;
}
.button {
    position: relative;
    left: 0;
    display: inline;
    width: 200px;
    height: 75px;
    background-color: lightgray;
    font-size: large;
    border-radius: 4px;
    border: 1px solid #ccc;
    margin: 0 10px 0;
    box-shadow: 0 0 2px #fff inset;
    -webkit-transform: perspective(100px) rotateX(30deg);
    -o-transform: rotateX(30deg);
    -ms-transform: rotateX(30deg);
    -moz-transform: perspective(100px) rotateX(30deg);
}
<div class="limit">
    <button data-tab="tab-1" class="button current">Car 1</button>
    <button data-tab="tab-2" class="button">Car 2</button>
    <button data-tab="tab-3" class="button">Car 3</button>
    <button data-tab="tab-4" class="button">Car 4</button>
    <button data-tab="tab-5" class="button">Car 5</button>
    <button data-tab="tab-6" class="button">Computer</button>
    <button data-tab="tab-7" class="button">Message</button>
    <button data-tab="tab-8" class="button">Nature</button>
    <button data-tab="tab-9" class="button">Power</button>
</div>

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

Decoding Labels for Content

Recently, I've been working on a VBA script that scrapes company reporting dates from the London Stock Exchange website. However, I encountered an issue as they have made changes to their web query interface. So, I've been trying to tweak the scr ...

Switching between table rows - managing open rows efficiently

Currently, I am working on an extensive database project involving pulling a large amount of data from a database. My focus is on displaying basic information in one visible row while concealing more detailed information in another row. By clicking the &ap ...

What is the optimal approach for managing script initialization on both desktop and mobile devices?

I have implemented a feature on my website that can detect whether the viewer is using a mobile device. Additionally, I have created a JavaScript script that adjusts settings based on whether the user is on a mobile device or not. However, I am wondering ...

What is the best way to halt the execution of content scripts in the active tab?

I am currently developing a Google Chrome Extension and have come across a bug that I am struggling to fix on my own. The extension works as intended when switching to Youtube's Dark Mode on a single tab. However, if you are on Youtube and open a new ...

Master the art of filtering rows in an HTML table based on a select option when the mouse is clicked

I am trying to create a table that displays only the rows selected in a dropdown menu. Here is an example: If "All" is selected, the table should display all rows. If "2017" is selected, the table should display only the rows that have "2017" in the sec ...

Issue with JQuery: object.id is returning as undefined even though it should have a value

While working with JQuery, I encountered a rather peculiar (or possibly foolish) error. The HTML code snippet in question is as follows: <input type="password" name="repeatPassword" id="id_repeatPassword" /> And within my javascript code, I have t ...

Arranging an array using jQuery JSON information

I've been working on sorting an array that is generated by a PHP script. The PHP script retrieves HTML files from a directory and then utilizes jQuery to fetch and display them on the webpage. Below is a snippet of my current code: <script> $( ...

The Vue DevTools are functioning as expected, but there seems to be an issue

Encountering a peculiar issue where the value displayed in Vue DevTools is accurate, matching what is expected in my data. When I first click on the "Edit" button for an item, the correct value appears in the browser window as intended. However, upon clic ...

Is there a way to automatically advance to the next question in Surveyjs without needing to click the Continue

I'm currently integrating SurveyJs into my web application. The first 3 pages of my survey contain HTML elements that I would like to automatically slide after a few seconds, similar to the functionality on the following sample site using SurveyJS: O ...

Issue with jQuery validate plugin (remote validation not working as expected)

Having trouble validating a user value with the jQuery Validation plugin. The validation appears to be working correctly and calling the web service function as intended. However, even when the server function returns a true/false result, the field is alwa ...

how to use jQuery to sort appended data

I have a loop that retrieves data from the server in descending order, but when I use "append()" to add the data, it doesn't maintain the correct sorting. For instance, the first row shows up in the second position. Is there a way to append the data ...

Embedding a string response containing HTML tags into an iframe

After making an AJAX call to a REST endpoint, I received HTML tags as a string response that I now need to bind to an iframe. The data contains HTML tags such as: var data="<html><head><title>iFrame</title></head><body> ...

Adjusting the style attributes for Material-UI Icons

I could use some assistance with changing the CSS property of MUI icons in order to assign a specific color when the icon is focused. I have implemented the icons in the header and am displaying different pages below them, so I would like to give each ac ...

What is the best way to format MySQL table data into rows and columns for display?

<?php mysql_connect('server', 'user', 'Pass'); mysql_select_db('add'); $query =mysql_query('select * from addimage'); while( $row = mysql_fetch_assoc($query) ) { echo "$row[url]"; } ?> This code ...

What could be causing the issue of node-sass generated CSS files not loading on the initial GET request?

I've set up a node express app and incorporated sass support for the CSS. However, when I attempt to access http://myhost.com:port/css/whatever.css, the whatever.css file is generated in the express_app_root/public/css directory as expected. The *.scs ...

Managing the Response from Google Geocode API in a Vue JS Component

I am facing an interesting challenge. I have a scenario where users can choose between two options - using their current location or entering a zip code. When a user inputs a zip code, I need to make a call to the Google geocode API to retrieve the central ...

Buttons in Jquery refusing to execute click function

I'm attempting to dynamically change the text below my form based on the user's selection of either 'yes' or 'no' through 2 radio buttons. The function getCats is responsible for setting catVal to the chosen radio button value ...

Ensure that adjacent elements operate independently from one another

The code snippet provided above showcases four components: StyledBreadcrumbs, FilterStatusCode, Filter, LinkedTable. The FilterStatusCode component enables users to input search data using TagInput. If the user inputs numerous tags, this component expands ...

Designing a fresh look for the developer portal on Azure API Management Services

Is there a way to customize the color of the navbar links in the fresh developer portal for different layouts? I have attempted using the designer tool provided by the portal, but it hasn't yielded any results. I also tried cloning the git repository ...

Experiencing a bug in the production build of my application involving Webpack, React, postCSS, and potentially other JavaScript code not injecting correctly

I've encountered an issue with my webpack.prod.config when building my assets, which may also be related to the JS Babel configuration. While I can successfully get it to work in the development build by inline CSS, the problem arises when attempting ...