Dynamic elements create an interactive horizontal scrolling experience

I have square elements that will be displayed in a row on the screen extension.

These elements are generated dynamically, starting with 2 and going up to 50. Depending on the screen size and number of elements, there may be overflow. In such cases, I want to show a horizontal scroll bar.

Check out the fiddle I experimented with here.

The code is as follows:

HTML

<div class="wrap-poltrona">
    <div class="poltrona"></div>
    <div class="poltrona"></div>
    ...
    <div class="poltrona"></div>
    <div class="poltrona"></div>
</div>

CSS

.wrap-poltrona{
}
.poltrona{
    width: 100px;
    height: 100px;
    background-color: red;
    float: left;
    margin: 5px;
}

Answer №1

To achieve the desired layout, consider using inline-block instead of float. Implement the following CSS:

.container{
  display:inline-block;
  white-space:nowrap;
  overflow:auto;
}
.box{
  display:inline-block;
}

You can view a working example at http://jsfiddle.net/K8Y9b/5/

Answer №2

One creative suggestion involves utilizing a viewport along with a sufficiently long div to accommodate all the objects in a single line.

Here's an example of how this can be implemented using HTML:

<div class="viewport">
    <div class="wrap">
        <div class="object"></div>
        <div class="object"></div>
        <div class="object"></div>
    </div>
</div>

And here's the corresponding CSS styling:

.viewport {
    width: 100%;
    height: 100px;
    overflow: auto;
}
.wrap {
    width: 1000000px;
}
.object {
    width: 100px;
    height: 100px;
    background-color: red;
    float: left;
    margin: 5px;
}

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

Font size transition on pseudo elements is not functioning properly in Internet Explorer when using the "em" unit

When I hover over, the font awesome icon and text on this transition increase in size. All browsers work well with this effect except for IE 11. This example demonstrates the same transition using px (class test1) and em (class test2). While using px wor ...

Bullet-point Progress Indicator in Bootstrap

Seeking guidance on how to create a Bootstrap progress bar with dots incorporated, similar to the image linked below. Any tips or resources where I can learn more about this technique? https://i.stack.imgur.com/BF8RH.jpg .progress { width: 278px; he ...

Creating a simulated dropdown menu using only CSS

I was able to create a select menu using only CSS, following some code I found. However, I am now facing an issue with overlaying divs. Whenever I hover or click on the "select menu", all the divs below it move down. I've attempted to adjust the z-i ...

The content inside the HTML body doesn't fully encompass the dimensions of the mobile screen

I am working on making my application flexible by using 100vw width and 100vh height for the components. Everything displays perfectly in any resolution on a computer browser, but when viewed on a mobile device, an empty background is drawn below the bod ...

Personalize Autocomplete CSS based on the TextField input in React Material UI when a value is present

In my current project, I am utilizing React Material Autocomplete fields, which includes a nested TextField. I have successfully implemented standard styles for when the field is empty and only the label is visible, as well as different styles for hover ef ...

Efficient Techniques for Deleting Rows in a Dynamic JavaScript Table

I'm facing an issue where I want to remove each line added by the user, one by one. However, my current program is removing all the rows from the table instead of just one at a time. The objective is to allow the user to remove a specific row if they ...

Learn how to display a web page in a tab view similar to the toggle device toolbar option

Is it possible to simulate the toggle device toolbar of a web page using JavaScript? https://i.stack.imgur.com/M9oB0.png For example, can we set up a webpage to always display in tab or mobile view like on YouTube? ...

Unicef's animated web content

Looking to learn more about gate animation and zoom page transition on the Unicef website? I want to incorporate these cool animations into my own project. Can someone provide me with a "keyword" or point me in the right direction to find information on ...

What is the reason behind line-height not affecting the clickable area when reduced?

I have been working on a personal project where I added thumbnails for images that can be scrolled through and clicked to set the main image. However, I encountered a strange issue. To demonstrate the problem, I created a Stackblitz project here: https:// ...

The Flowbite CSS plugin seems to be malfunctioning when attempting to include it within the tailwind.config.js file

Incorporating Flowbite (both JS and CSS) into my application has been a bit of a challenge. I managed to successfully insert the JS using Webpack and import 'flowbite' in the entry point JS file. As for the CSS, I followed the documentation and ...

Looking to display a div with both a plus and minus icon? Having trouble getting a div to show with left margin? Need assistance hiding or showing div text

Can someone please review this source code? Here is the demo link: http://jsfiddle.net/bala2024/nvR2S/40/ $('.expand').click(function(){ $(this).stop().animate({ width:'73%', height:'130px' }); $( ...

Stop SCSS from processing CSS variables in Angular-CLI

I am currently using Angular5 with sass v1.3.2. My goal is to dynamically change a color that is widely used in the scss files of my single page app without having to recompile new files. This color is globally defined in my _variables.css as: $brand: # ...

"Learn the trick to concealing a modal and unveiling a different one with the power of jquery

Whenever I try to open a modal, then click on a div within the modal in order to close it and open another one, I encounter an issue. The problem is that upon closing the first modal and attempting to display the second one, only the background of the seco ...

Ways to retrieve a JSON element and incorporate it into a CSS styling

Can someone assist me in converting a JSON object for use in CSS? I've attempted to do this using Vue.js, creating a map legend with v-for to generate the legend. However, if there is an alternative method that allows me to take a JSON object and ins ...

Using Jquery to create a slideshow with a div that is set to absolute

<!DOCTYPE html> <html> <head> <script> $(document).ready(function(){ $("#flip").click(function(){ $("#panel").slideDown("slow"); }); }); ...

What is the best method for positioning span content above all other elements without having it wrap around them?

Each form element on my page is accompanied by a span that displays an error message, if applicable. The layout consists of two columns: left and right. I am struggling to make the span display seamlessly from the left column all the way across the page wi ...

Tips for avoiding word fragmentation in <pre> code blocks

pre { white-space: pre-wrap; /* CSS 3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ overflo ...

How can I align two div buttons at the top and bottom to appear on the left and right sides?

How can I change the position of two buttons from top and bottom to left and right as shown in the second image? I am utilizing Floating Vue, so the buttons will be contained within a div. Is it feasible to adjust their position accordingly? Check out th ...

Make sure your website design is responsive by setting the body to the device's

I'm struggling to make the body of my page responsive for mobile users. Whenever I try using this line of code, it just creates a messy layout. Any advice on how to fix this? <meta name="viewport" content="width=device-width" ...

Listening for JS events on a CSS class called "int-only" which only accepts

Having an issue: I'm encountering a problem with this PHP code: <?php for($i = 0; $i < sizeof($floating_ips_json["floating_ips"]); $i++){ ?> <tr class="details-control-<?php echo $i; ?> cursor-pointer"> <t ...