Preventing Floating Divs from Clearing or Wrapping

I'm currently working on a unique project involving floating divs that I would like to spin endlessly in a horizontal line without wrapping. These divs must remain within a specific width container, and my goal is to implement left and right buttons to scroll through the items instead of using a scrollbar.

However, I'm facing an issue where the divs wrap around once they reach the end of the parent container. Is there a way to prevent this wrapping behavior? Once I solve that, my next step is to use jQuery to enable horizontal movement when the user clicks on the left or right arrows.

You can find the code and view the fiddle I've created below:

http://jsfiddle.net/stfzy/8/

HTML:

<div id='container'>
    <div id='arrowL'>
    </div>
    <div id='arrowR'>
    </div>
    <div class='list'>
        <div class='item'>
        </div>
        <div class='item'>
        </div>
        <div class='item'>
        </div>
        <div class='item'>
        </div>

    </div>

CSS:

#container{
width:340px;
    height:50px;
}

.list{
    background:grey;
width:300px;
    height:50px;
    float:left;
}


#arrowR{
background:yellow;
    width:20px;
    height:50px;
    float:right;
}


#arrowL{
background:yellow;
    width:20px;
    height:50px;
    float:left;
}

.item{
    background:green;
width:140px;
    height:40px;
    margin:5px;
    float:left;
}

Any assistance or advice on how to achieve this functionality would be greatly appreciated. Thank you!

Answer №1

One solution is to wrap the list class inside a container with overflow:hidden. From there, you can utilize JQuery to manipulate the inner div as needed.

Check out this example on JSFiddle

#list-container {
overflow:hidden;    
width: 300px;   
}

.list{
background:grey;
min-width:700px;
float:left;
}

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

Looking for a solution to align the header properly in your React app?

Struggling with aligning a header? The CSS property of the header is inherited from the app's CSS file. For example, in the image below, "Our Mission" is the header that needs to be left-aligned. Looking for some assistance here. You can find the app. ...

The background-color of a single child within an absolutely positioned element in Chrome may not be displayed if the element has a z-index and overflow scrolling

This test page has been created to showcase the issue: <html> <head> <style> .panel { position: absolute; width: 326px; max-height: 200px; overflow: scroll; z-index: 1000; } .item-container { width: 100%; list-style: none; ...

Accessing JSON data from a .NET web service using JQuery

Having some issues with populating events from a database using FullCalendar module. The JSON string received from a C# web service is not parsing correctly, resulting in "undefined" alerts when trying to access the data. In Firebug, the response string l ...

Encountering a maximum call stack size exceeded error while using toggle with bootstrap 4

Currently, I am working with asp.net, using Bootstrap 4 and Jquery 3.3.1 to implement bootstrap4-toggle. My setup includes 3 inputs, each with a unique ID. Upon loading, the first toggle is set to on. I have an onchange event that triggers whenever a check ...

The remove() function successfully removes options from the select box, but the hide() function did

I am trying to create functionality where select box options are shown or hidden based on the input field value. Surprisingly, this only seems to work with $('thisOption') when removing (), but not with: $('thisOption').hide() // or: ...

How come the list of IDs does not get sent by jQuery to the Razor page even though it displays correctly on the console log?

While working on an asp.net razor page, I encountered an issue when sending a list of IDs from jQuery ajax to razor. The razor page displays the count as 0, even though the console in the browser shows two items in the array. public JsonResult OnGetListIdU ...

The color attribute in a Div container remains the same even when hovering over it

Hello everyone, I am new to stack overflow so please bear with me. I am currently working on this small webpage for my IT course and I have encountered a significant issue. .float1 { float:right; background-color:#A3635C; margin-top: 150px; ...

Getting the value of dynamically generated buttons when they are clicked in PHP - a simple guide

In my PHP code, I have successfully created dynamic buttons. However, I am facing an issue where I need to retrieve the value of a specific button when it is clicked, and populate all the information in a form. Below is the code snippet for handling the b ...

How can I use CSS to make a child element in a grid layout stretch horizontally to full width?

I am currently working on designing a grid layout that will display a child element when clicked. Here is what I have in mind: [ link1 ] [ link2 ] [ link3 ] [ link4 ] [ link4 ] [ link4 ] When clicked, it will turn into: [ link1 ] [ link2 ] ...

tips for repurposing a jquery function

Similar Question: JQuery: Issue with $(window).resize() not triggering on page load In my jQuery code snippet below, I am trying to make a function work both on window resize and page load without duplicating the code. The current implementation works ...

When using jQuery, the search for the ID within an iframe may fail if the specified condition

I have a scenario where I need to dynamically generate an iframe and its corresponding id. Now, I need to check if the generated id already exists or not. This is what my code looks like: function createIframe(intxnId){ alert("The Id is : "+"$(&apo ...

Modify the color of the text for the initial letter appearing in the sentence

I am currently exploring the possibility of altering the font color of the initial instance of a letter in a div. For example, if the String were 'The text' and I desired to make the color of 'e' yellow, then only the first e would be i ...

Adjusting the columns of two tables when one table is held in place

My dilemma involves managing two tables: In the scenario, Table 1 remains fixed in place serving as a header that is always visible. Meanwhile, Table 2 acts as the data table. I am not a fan of fixed widths for my tables; I prefer them to dynamically adj ...

New space is formed as the input box gains focus on the signin field

I'm currently working on a sign-in page and implementing JQuery. Everything seems to be functioning properly except for a minor issue. The problem is that when the password field gains focus, it creates extra space in IE 8 and later versions only. Th ...

trouble with jquery radiobutton switching

When using two radio buttons to toggle the activation/inactivation of certain fields in a form, an issue arises when sending data via ajax and reopening the form without refreshing the page. The radio buttons lose their functionality and remain broken upon ...

Steps for creating duplicates of jQuery elements

My Objective I am currently working on a project that involves allowing users to modify an SVG file based on input, such as text formatting (bold, italic, etc.). It is important that the user can revert back to the original template without having to relo ...

Laravel's Yajra Datatable is experiencing difficulty with wrapping text on a particular column

I'm currently working on a project that utilizes Yajra Laravel-datatables for managing data tables. Incorporated Yajra package installed through composer.json The issue I'm encountering involves text wrapping, as shown in the screenshot below, ...

What is the method for creating a hovering triangle on a particular element?

My navigation bar consists of two parts. On the left side, there is a logo image, and on the right side, there are 4 list elements. I am attempting to make a triangle appear at the bottom of the element when hovered. I have floated the list to the right an ...

Transforming an HTML and Javascript Project into a Standalone Application

Currently, I am engaged in a side project to enhance my skills in HTML/CSS/JavaScript. I have been using Aptana as my primary tool for coding, and it is configured to run smoothly in a browser environment. Specifically, the project I am working on is a te ...

Dealing with Errors in AJAX using FluentValidation with .NET Core

How can I handle errors in FluentValidation when using form post with AJAX / jQuery? Here is my JavaScript: function Create(controlId: any) { var control = $('#' + controlId); var controller = control.data('controller'); v ...