Tips for preventing elements from wrapping in a lengthy list and using scrollbars in Firefox

When dealing with a lengthy flex list, the items (buttons) should wrap when there is not enough space available (using flex-wrap). However, an issue arises in Firefox where the items are wrapped once a scrollbar appears, even if there is ample space.

In contrast, Chrome displays the buttons side by side as intended.

(Vue is used here for simplicity in maintaining the HTML structure. Essentially, it generates the text/button element 30 times)

new Vue({
  el: "#app",
})
body, html {
  margin: 0;
}

.container {
  position: absolute; 
  height: 100vh; 
  overflow: auto;
}

.row {
  display: flex;
  flex-wrap: wrap;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div class="container" id="app">
  <div v-for="(i, index) in 30" :index="i">
    Text
    <div class="row">
      <button>Button 1</button>
      <button>Button 2</button>
    </div>
    <hr />
  </div>
</div>

Answer №1

Upon inspection, I noticed that the flex container successfully occupies the entire available space in the viewport as intended with height: 100vh;. This observation was made while using Firefox.

However, it seems like your current issue lies not in the vertical space but rather in correctly displaying elements inline. To rectify this, ensure that your buttons have display: inline-block; property applied from the start.

Another suggestion would be to adjust the width of the closest parent element. Initially, I implemented a rule for the parent elements .container > div setting their widths to width: fit-content;. Subsequently, I transferred this rule to the .container, and effectively managed the scrollbar feature by employing overflow-y: scroll.

It's worth mentioning that when utilizing overflow: auto, the scrollbar will only appear when necessary, but the container size won't consider whether the scrollbar will be displayed or not. Thus, if they do appear, they might cover some content due to occupying inner space.

In contrast, applying overflow: scroll will continuously show the scrollbar while always factoring them into the container size.

To make sure the container size adapts even with overflow: auto, you can explore options such as:

scrollbar-gutter: stable;

https://developer.mozilla.org/en-US/docs/Web/CSS/scrollbar-gutter

For a more precise control over the container width, you could validate via JavaScript whether the content overflows the container. If so, dynamically add (or remove in reverse scenario) the CSS attribute overflow: scroll.

I also included box-sizing: border-box to prevent containers from taking up additional vertical space.

The provided demo showcases two adjacent "apps," one featuring a container with non-overflowing content (hence no scrollbar), and the other with overflowing content (thus exhibiting a scrollbar):

This solution ensures the containers are regularly refreshed in case of window resizing, adjusting the scrollbars based on changes in content overflow conditions.

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

Can Google Charts columns be customized with different colors?

Is it possible to modify the colors of both columns in Google's material column chart? Here is the code I am using for options: var options = { chart: { title: 'Event Posting', subtitle: 'Kairos event p ...

Navigate to the specific page using the router-link with the designated path

I have 10 different filters displayed in a table and I want each filter name to link to a specific page. Here is an example of my table row: <md-table-row v-for="(row, index) in manage" :key="index"> In the first cell of the table, I'm trying ...

Utilizing Django framework for crafting a captivating homepage

Successfully set up the django framework and developed an app for my homepage. I added the app to the settings in the project folder and was able to get the HTML running smoothly. However, I am experiencing issues with styling as the CSS won't apply. ...

The program waited for 60 seconds for the element to become clickable in the Selenium webdriver, but it timed out

I am currently working on Selenium web driver and trying to locate the element with the ID visualizationId, but I keep encountering an error. Below is the code snippet where the error occurs: Actions actions1 = new Actions(driver); WebElement dBox1= ((new ...

Discovering the dimensions of a disabled attribute within a table using XPath in Selenium with Java

I'm attempting to determine the number of columns in a specific table, but some are disabled - I'd like to know if it's possible to get the count without including the disabled ones (only counting the visible columns). As you can see in the ...

What is the best way to incorporate multiple HTML buttons that utilize the same JavaScript function within looped results?

My HTML page contains the following codes: <input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="metin" placeholder="Geben Sie Artikel Nr" style="width: 30%;"/><br/><br/> <input type="button" class="sin ...

Is there a way to access a CSV file containing a comprehensive list of days and months?

I am in the process of designing a booking form for a website, and the client has specified that they prefer a drop-down menu for selecting dates rather than a traditional calendar. To achieve this, I plan to utilize gravity forms. For the date options, I ...

How can HTML output be automatically indented?

Seeking a way to automatically indent the HTML generated by my PHP script. I currently use HTML Purifier for validating internal textbox inputs, but I have reservations about using HTML Tidy due to its lack of active development and numerous reported bugs ...

Basic HTML code that displays either one or two columns based on the width of the screen

My monitoring website displays dynamic rrd graphs in png format with fixed dimensions. I am looking to adjust the layout based on browser window size - showing the graphs in 1 column if the width is below a certain threshold, and in 2 columns if it exceed ...

I noticed an excess of white space on the right side of my Angular website

Check out my website here. Everything seems to be functioning correctly, however, there is an issue with scrolling on mobile. It should only scroll up and down, not left and right! I have noticed a strange white space on the right side of my site when view ...

Convert JSON data from jQuery into a modal form within a div element

I am currently working on an MVC application and attempting to populate a bootstrap modal form with data from the server. My approach involves: 1) Loading a grid with various IDs, each linked to a javascript onclick function. 2) The function retrieves th ...

Tips for avoiding duplicate Id tags while using Ajax in MVC

Hello everyone, I am curious to learn about the precautions and techniques you employ when working with Ajax or MVC functions such as @Html.Action in order to effectively manage and prevent duplicate Ids for Html tags. In addition, how does the page handl ...

Guide to implementing proportional height for an element using JQuery 3.3.1

I am currently working on dynamically setting the heights of elements with a specific class using JQuery in order to achieve a 16:10 ratio based on their width. However, I'm encountering an issue where the height doesn't seem to be applied and re ...

How do I align the Close button to the right in a Bootstrap 5 toast message?

To create a Bootstrap 5 toast, I use the following code: <div id="liveToast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true"> <div class="toast-header"> ...

Ways to troubleshoot the CSS padding issue

I've been wrestling with this landing page for the past day and I just can't seem to get the form section right. Take a look at this link! The form at the bottom of the page is all over the place. Below is the CSS snippet that I have been using ...

Tips for overlapping children in a column flex direction while maintaining the parents' positioning

Currently, I am working with two parent flex items, arranged with flex-direction: column. Within the first parent, there are two children. However, one of the children is optional and may be removed at times. I aim to have the optional child displayed on ...

Adding HTML content inside an iFrame at a specific cursor position in Internet Explorer

Does anyone know a method to insert HTML into an iFrame specifically for IE? I have been using execCommand insertHtml in Chrome and Firefox, but it doesn't seem to work in IE. I was able to paste HTML into a content editable div using pasteHTML, howe ...

Some web browsers do not support video html5, except for Google Chrome

Not all browsers support HTML5 video, with the exception of Google Chrome. In Firefox, there may be a message saying "No video with supported format and MIME type found." To embed a video in your page, you can use the following code: <video width="3 ...

There appears to be a malfunction with certain hyperlinks on the table

There seems to be an issue with the four links in the third column, first, second, third, and fourth rows (Order Form PDF, Rental App PDF, Married Rental PDF, and Consent Form PDF) as they are not functioning properly. Below is the provided code snippet: ...

Efficiently rearranging elements by adjusting their top values techniques

My iPhone lockscreen theme features various elements displaying weather facts such as text and small images. Currently, these elements are positioned in the middle of the screen and I want to move them all to the top. Each element has a unique position abs ...