Stop divs from wrapping without introducing default scrolling

I'm a bit confused about something: on the website for the Polymer Project, they have tabs that can scroll horizontally if there are too many. I want to create a similar effect, but I'm struggling to find a way to prevent the tab <div> elements from wrapping while also enabling scrolling. It seems like JavaScript will be necessary for this task. Is it possible to implement a custom scrollbar instead?

How can I achieve this without using jQuery? That would be the preferred solution.

Answer №1

To compare the calculated width of the inner div with the set width of the outer div, you can use either plain JavaScript or jQuery. If #inner is wider than #outer, apply a class to one of the divs to adjust their display. If not, remove the class.

The structure:

<div id="outer">
  <div id="inner">
  <div class="scroll-button"></div>
   <!-- include your tabs here -->
  <div class="scroll-button"></div>
  </div>
</div>

The CSS styling:

#outer{
  width:500px;
  overflow-x:hidden;
}
#outer .scroll-buttons{
  display:none;
}
#outer.has-scroll-buttons .scroll-button{
  display:block;
}

Answer №2

Set a specific height for the divs while allowing their length to adjust dynamically based on the number of columns you desire in each div.

What's the reluctance towards using jquery?

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

Incorporating a function within a Handlebars Helper

I have successfully registered a helper in my handlebars template, but now I want to incorporate $.getJSON into it to display some results from an ajax request. Below is the javascript code (written in coffee) Handlebars.registerHelper('getNea ...

There appears to be an error in the @media CSS code that needs to be corrected

Attempting to use an @media query to adjust the height of an element on my website for mobile users. However, I am struggling to make the code work properly. Any assistance in understanding what mistake I'm making and guiding me in the correct directi ...

Problem with Google+ Button Alignment

I arranged my social media buttons in a row - Twitter, Facebook & Google+. The issue is that the Google+ button is not aligning properly. It appears to be spaced out about 3 times further than the Twitter and Facebook buttons. I attempted adjusting the p ...

Creating a universal variable that can be accessed across multiple files

In my nodejs project, I have implemented a dynamic form that expands when the user clicks "add question". This functionality is achieved through the createUX.js file, which appends additional divs to the html form on button click. The file also maintains a ...

Exploring object key-value pairs using the 'for in' loop in JavaScript

Embarking on a project to develop a quiz in javascript, I am starting with an array that holds the questions as anonymous objects. var allQuestions = [{ "question": "Who was Luke's wingman in the battle at Hoth?", "choices": ["Dak", "Biggs", "Wedge", ...

Revise the "Add to Cart" button (form) to make selecting a variant mandatory

At our store, we've noticed that customers often forget to select a size or version before clicking "Add to Cart" on product pages, leading to cart abandonment. We want to add code that prevents the button from working unless a variant has been chosen ...

Exploring Enum properties within an angular js select drop down

I am working with an enum in Java that looks like this: public enum myEnum{ enum1("enumDisplayVal1"), enum2("enumDisplayVal2") myEnum(String displayValue) { this.displayValue = displayValue;} private String displayValue; public String getDisp ...

Using jQuery to pass an array as part of an object literal for AJAX data transmission

I'm currently facing an issue with passing a dynamic object to jQuery ajax data in order to mimic the structure of serialized form data. This problem arises when I have a form with inputs using an array for the name, as shown below: <input type="t ...

Extract specific form data to use in a jQuery.ajax request

Having trouble extracting the current selected value from a dropdown form in AJAX URL. The Form: <form name="sortby"> <select name="order_by" onchange="myFunction()"> <option<?php if(isset($_GET['order_by']) && ...

Prevent incorrect data input by users - Enhancing JavaScript IP address validation

I have been trying to create a masked input field for entering IP addresses, but every solution I come across seems to have some flaws. The best solution I found so far is , but it still allows values higher than 255 to be entered. It works fine initially ...

What is the best way to use SQL and Flask to automatically fill out a form based on a selection made from a

Looking for assistance with populating an HTML form by selecting a company from a dropdown menu. The desired result is similar to the example found here, using SQL and Flask. I'm unsure of how to retrieve the selected value from the <option> ta ...

Struggled to enable scroll functionality with Tailwind CSS in Next.js version 13

I am currently working on a project in next.js 13 where I attempted to incorporate a scroll bar using tailwind css. <div className="flex w-[1020px] p-4 overflow-x-scroll"> <div className={`w-[300px] h-[300px] self-center rela ...

Creating a perfectly centered button with Bootstrap

Just diving into the world of bootstrap and jquery while working on a school project. Bootstrap is being used to ensure responsiveness in my application. Facing an issue where the buttons are aligning at the top of their respective columns instead of in th ...

Creating adaptable background images with fullpage.js

I'm currently utilizing fullpage.js for parallax scrolling. I'm wondering if there's a way to make the background images adjust responsively when I resize my window. Check out the documentation here: https://github.com/alvarotrigo/fullPage. ...

Updating the title with respect to the current route in AngularJS 1

Is it possible to dynamically change the title displayed in a header based on the current route provided by the router, even when outside of the controller scope? For example, I have a mainMenu controller that is loaded when a specific route is called. The ...

Utilizing React TypeScript to extract the contents of a node from a reference

Is it possible to pass the React ref to the document range's .selectNodeContents() function? I'm encountering this error: Argument of type 'HTMLDivElement | null' is not assignable to parameter of type 'Node'. Type 'nul ...

Is there a way to create a footer that will only appear once the entire content has been read?

While utilizing Ionic, my code includes the following structure: <ion-header></ion-header> <ion-content> <div *ngFor="let publisher of publishers" class="contentspacing"> <div class="border-div"> <d ...

What is the method for allowing tooltips to disappear when clicked on?

Is there a way to prevent a tooltip from hiding unless it is clicked on? Would using a popover be a better solution? var Button = document.querySelector('.Button'); $(Button).attr("data-toggle", "tooltip"); $(Button).attr("data-placement", "top ...

What is a callback function tied to a specific URL?

I need to implement a functionality in my web application where users can click on a link within a datatable, which will then load a new table on a separate page. This new table should only display rows that have the same id as the row that was clicked on ...

Implementing RXJS subscription using a Subject object

What is the benefit of using "Subscribe providing subject" and what does this entail: 1- The purpose of using subscribe providing subject import { Subject, from } from 'rxjs'; const newSubject = new Subject<number>(); newSubject.subscr ...