Adjust the div's width dynamically based on its content

I've spent a lot of time reading through the questions and answers on this site, but I still can't figure out why my container won't allow horizontal scrolling for my smaller divs.

CSS

#theLoopTasksLabels {
    width:90%;
    height:90px;
    position:relative;
    margin-top: 60px;
    margin-left:10px;
    overflow-y: hidden;
    overflow-x: scroll;
    white-space: nowrap;
    display: inline-block;
    float:left;

}

#categoryTasksLabels {
    height:70px;
    padding:5px;
    margin-left: 10px;
}

#categoryTasksLabels  > h6 {
    padding-top:2px;
    padding-left:10px;
    color:#B6B6B6;
}


#loopsTasksLabels {
    width: 110%;
    height: 90px;
    display: inline-block;
    float:left;

}

#loopsTasksLabels > div {
    display: inline-block;
    float:left;
}

#circleTaskLabels {
    padding:5px;
    border-radius: 3px;
    display: inline-block;
    margin-top:4px;
    color:#fbfbfb;
}

HTML

<div id="theLoopTasksLabels">


        <div id="loopsTasksLabels">

                <div id="categoryTasksLabels">

                    <div id="circleTaskLabels" style="background-color:#eaa5a2">Label</div> <br>
                    <h6><span> 4</span> | <span>6</span></h6>

                </div>

                <div id="categoryTasksLabels">

                    <div id="circleTaskLabels" style="background-color:#eaa5a2">Label</div> <br>
                    <h6><span> 4</span> | <span>6</span></h6>

                </div>

                <div id="categoryTasksLabels">

                    <div id="circleTaskLabels" style="background-color:#eaa5a2">Label</div> <br>
                    <h6><span> 4</span> | <span>6</span></h6>

                </div>

        </div>


</div>

Despite following advice from other answers, I still can't get it to work. The horizontal scroll only kicks in when the content exceeds the width of the

<div id="categoryTasksLabels">
, which varies depending on how many the user creates. I'm at a loss as to what to try next.

Thank you for any help you can provide.

Answer №1

First and foremost, it's always best to utilize classes instead of IDs for styling multiple elements.

In addition, I found that eliminating the "float: left" from ".loopsTasksLabels > div" resolved the issue for me.

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

Manipulate classes based on scrolling (Wordpress)

Trying to manipulate a widget by adding and removing classes based on user scroll behavior has proven to be quite challenging. Specifically, I aim to add one class when the user scrolls down by 50px and remove it when they scroll back up. Website: Check o ...

Creating immersive experiences with fabric.js in fullscreen mode on canvas

Attempting to implement a fullscreen mode (using HTML5 fullscreen) for a canvas object created with Fabric.js. var canvas = fabricCanvas.getSelectionElement(); if(canvas.requestFullScreen) { canvas.requestFullScreen(); } else if(canvas.webkitRequestFu ...

How to remove an image input type using jQuery

Can anyone provide insight into the issue with these scripts? I am attempting to remove an input when it is clicked. The input is of type image, so CSS cannot be used. I have tried using JavaScript but it doesn't seem to be working. HTML <!doctyp ...

Automatically add a table row at the bottom displaying the overall calculation

I have data to display in an HTML table. The data is coming from a third-party server (PHP) using AJAX requests. The data is currently being displayed effectively with the following code: <table id="tbl-product"> <tr> < ...

Tips for converting JSON information on a website and inserting it into a designated division?

I've recently delved into front-end development, searching for solutions and hints without much success. I'm currently in the process of building my first website, specifically a "find recipes" website. Lacking knowledge of API calls, I created a ...

Styling various versions of a <button> using Styled Components

In my app, I have a basic colored button that needs to change its color depending on the UI state: const StyledButton = styled.button` & { border: 0; color: white; cursor: pointer; } &:hover { background-color: ${(props) => ...

Ways to retrieve element values in JavaScript without relying on IDs

Imagine for a moment that I had the subsequent code: <div class="post"> <h2 itemprop="name"> <a href="http://www.example.com">The Post Title</a> </h2> <div class="details"> <span> <em class="date" ...

Maintaining the position of an image during animation movements

I am experiencing an issue with a grid of images where, upon clicking one image, all the other images move down. However, the remaining image is pulled to the top left corner. I suspect this is happening because by removing the other images, the remaining ...

Submitting a form using jQuery when the form is nested within a table

Why are forms not submitting with jQuery inside tables? I've tested form submission outside of a table and it works fine, but as soon as I wrap it inside a table, it stops working. I tried adding an extra parent() to adjust for the form moving above t ...

Web page containing information from IPv6 and IPv4 sources exclusively

Is it possible to have an HTML5 page accessible through both IPv4 and IPv6, while only allowing CSS style and JavaScript from other domains via IPv4? Unfortunately, it seems that this setup does not function properly for pure IPv6 connections. Will th ...

If the condition evaluates to true, then all other conditions will be skipped

xyz.html <p id = x ngClick = close($event)></p> <p id = y ngClick = close($event)></p> <p id = z ngClick = close($event)></p> <h1 id = a ngClick = close()></h1> xyz.js function close(event) if (event.targe ...

Excessive white space is appearing below the title of my card when using Bootstrap 4

As a beginner in PHP and Bootstrap, I encountered an issue with my login form. Everything was working fine until I added <link rel="stylesheet" type="text/css" href="styles.css"> to my header. I cannot simply remove these links from my header as I w ...

Incorporate an onclick event to the elements within the array

I'm currently working on iterating over an array and adding an onclick event to each element. My goal is to be able to click on each div and have them log their values in the console. However, I am facing a challenge in applying the onclick event to e ...

Error: Disappearing textarea textContent in HTML/TS occurs when creating a new textarea or clicking a button

I've encountered an issue with my HTML page that consists of several textareas. I have a function in place to dynamically add additional textareas using document.getElementById("textAreas").innerHTML += '<textarea class="textArea"></text ...

Breaking apart a string and mapping it to specific fields

My issue is relatively straightforward. Upon loading my page, a long string representing an address is generated. For example: 101, Dalmations Avenue, Miami, Florida, USA, 908343 With the help of jQuery, I can split the string using: var address = sel.o ...

Refreshing a webpage is not necessary when using a JQuery form within a div

I need help with some code I have. In my index.html file, there is a div: <div id="logindiv"> <?php require_once('login.php'); ?> </div> This div is utilized with jQuery: <script type="text/javascript"> $(document ...

"An issue arises with jqPlot axes and legend when exporting images, as they are not rendering

After successfully rendering my jqPlot, I encountered an issue when exporting it as an image. The axes text and legend labels aren't displaying correctly in the exported image - the text seems to be shifting. Here's a comparison of the actual plo ...

What is the best way to incorporate a fixed-position button that spans the full width of the screen?

After trying numerous solutions on stackoverflow, I have yet to find one that works for me. a.buttongc { border-radius: 5px; background: #f5b220; color: #fff; font-size: 17px; height: 44px; line-height: 42px; color: #fff; text-decoration ...

Do you think it's achievable to modify the color using CSS's order attribute?

When I look at the code in Firefox's inspector, I notice this : element { order:35; } Can a color be assigned to it? I am customizing my year outlook calendar and have set a particular day to display in a different color. But when I click on the mo ...

What is the process for creating a selector that links to an element that has been dynamically generated?

Can anyone help me figure out how to create a selector that links to a dynamically created element without using an event on the dynamic element? By dynamically created element, I mean an element that is not present in the HTML at the beginning. I know t ...