How do you prevent items from shrinking in a flex container when they have more content?

I am facing an issue with a flex container where the items are set in a row. Once it reaches the end of the viewport width, I want it to overflow-x: scroll. However, instead of enabling scrolling, all items shrink when more items are added to fit the screen.

Is there a way to allow overflow and still enable scrolling in the x-direction without shrinking the items?

.footer-container {
  width: 100%;
  height: 12rem;
  background-color: #fff;
  position: fixed;
  bottom: 0;
  display: flex;
  overflow-x: scroll;
  padding: 1rem;
  animation: slide-up;
  animation-duration: 1s;
  visibility: hidden;
  opacity: 0;
}

.footer-items {
  background-color: rgb(214, 218, 219);
  width: 17rem;
  list-style-type: none;
  border-radius: 4px;
  margin-right: 1.5rem;
  padding: 1rem;
  font-size: 1.5rem;
  position: relative;
  animation: fade-in;
  animation-duration: 2s;
  display: flex;
}

.side-col {
  display: flex;
  flex-direction: column;
}

.cart-image {
  min-width: 10rem;
  height: 6rem;
}

.cart-price {
  position: absolute;
  top: 50%;
  right: 1rem;
  transform: translateY(-50%);
  font-weight: 600;
}
<footer class="footer">
  <ul class="footer-container">
    <li class="footer-items">
      <div class="side-col">
        <p>Bike<p/>
        <img class="cart-image" src="bike.png"/>
      </div> 
    <span class="cart-price">$2345</span> 
    </li> 
  </ul>
</footer>

Here is how it looks without overflowing items

and with overflowing items

Answer №1

Correct me if I am wrong, simply include flex-shrink: 0; to the item that should not shrink. If there are any other requirements, please inform me.

You can refer to the documentation on flex-shrink here.

.footer-container {
  width: 100%;
  height: 12rem;
  background-color: #fff;
  position: fixed;
  bottom: 0;
  display: flex;
  overflow-x: scroll;
  padding: 1rem;
  animation: slide-up;
  animation-duration: 1s;
}

.footer-items {
  background-color: rgb(214, 218, 219);
  width: 17rem;
  flex-shrink: 0; /*add this property only*/
  list-style-type: none;
  border-radius: 4px;
  margin-right: 1.5rem;
  padding: 1rem;
  font-size: 1.5rem;
  position: relative;
  animation: fade-in;
  animation-duration: 2s;
  display: flex;
}

.side-col {
  display: flex;
  flex-direction: column;
}

.cart-image {
  min-width: 10rem;
  height: 6rem;
}

.cart-price {
  position: absolute;
  top: 50%;
  right: 1rem;
  transform: translateY(-50%);
  font-weight: 600;
}
<footer class="footer">
  <ul class="footer-container">
    <li class="footer-items">
      <div class="side-col">
        <p>Bike<p/>
        <img class="cart-image" src="bike.png"/>
      </div> 
    <span class="cart-price">$2345</span> 
    </li> 
    <li class="footer-items">
      <div class="side-col">
        <p>Bike<p/>
        <img class="cart-image" src="bike.png"/>
      </div> 
    <span class="cart-price">$2345</span> 
    </li> 
    <li class="footer-items">
      <div class="side-col">
        <p>Bike<p/>
        <img class="cart-image" src="bike.png"/>
      </div> 
    <span class="cart-price">$2345</span> 
    </li> 
    <li class="footer-items">
      <div class="side-col">
        <p>Bike<p/>
        <img class="cart-image" src="bike.png"/>
      </div> 
    <span class="cart-price">$2345</span> 
    </li> 
    <li class="footer-items">
      <div class="side-col">
        <p>Bike<p/>
        <img class="cart-image" src="bike.png"/>
      </div> 
    <span class="cart-price">$2345</span> 
    </li> 
  </ul>
</footer>

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

Tips for customizing the event target appearance in Angular 2?

After following the steps outlined in this particular blog post (section 3, event binding), I successfully added an event listener to my component class. I can confirm that it responds when the mouse enters and exits. <p class="title" (mouseenter)="unf ...

Troubleshooting the issue: Unable to shift a div to the left in a Rails app using jQuery and CSS when a mouseover event occurs

Hey there, I'm working on a div that contains a map. My goal is to have the width of the div change from 80% to 50% when a user hovers over it. This will create space on the right side for an image to appear. I've been looking up examples of jqu ...

Issue with Javascript/Jquery functionality within a PHP script

I have been attempting to incorporate a multi-select feature (view at http://jsfiddle.net/eUDRV/318/) into my PHP webpage. While I am able to display the table as desired, pressing the buttons to move elements from one side to another does not trigger any ...

Tips on displaying the number of items ordered above the cart icon

Hey there, I've been attempting to place a number in the top left corner of a cart icon without success. My goal is to achieve a result similar to the image shown here: enter image description here Here is the code snippet I've been using: < ...

Tips for Creating a Responsive Homepage

I'm new to CSS and trying to create a responsive design for mobile IE. Currently, the page appears blank on IE but works fine on Google Chrome and other browsers :-) Here are the code snippets I have used: HTML: <div class="main"> <div ...

Organizing list items into vertical columns

Could you help me with UL/LI syntax and how to create a wrapping list? For example, I would like to display: 1 2 3 4 5 6 As: 1 4 2 5 3 6 Currently, I have a header, content, and footer all set with specified heights. I want the list to wrap when ...

Customizing the primary CSS style of an element without the need to individually reset every property

Is there a way to reset just one property of a selector that has multiple properties stored in main.css, without listing all the properties and setting them to default values? I always struggle with CSS interference and constantly need to reset properties ...

Angular JS is encountering an issue where the promise object is failing to render correctly

I'm currently learning Angular and I have a question about fetching custom errors from a promise object in Angular JS. I can't seem to display the custom error message on my HTML page. What am I missing? Below is my HTML file - <!DOCTYPE htm ...

Vue.js: Issue with applying class binding while iterating over an object

I've been working with an object data that looks like this: object = { "2020092020-08-01":{ "value":"123", "id_number":"202009" }, "2020092020-09-01":{ "value& ...

What methods can I use to verify that the form data has been effectively stored in the database?

Here's the code snippet I've been working on: <?php // Establishing connection to the database require("database.php"); try{ // Prepare and bind parameters $stmt = $conn->prepare("INSERT INTO clients (phonenumber, firstname) VALUES (:ph ...

Generate a new JSON reply using the current response

I received a JSON response that contains values for week 1, week 2, week 3, and week 4 under the 'week' key, along with counts based on categories (meetingHash) and weeks. I attempted to merge this data using the .reduce method but without succes ...

Use jQuery to retrieve HTML content excluding comments

Take a look at the code snippet below. HTML: <div> <p>sdfsdfsfsf</p> <!--<p>testing</p>--> </div> JQUERY $(document).ready(function(){ alert($("div").html()); }); OUTPUT <p>sdfsdfsfsf</p> & ...

Mantine - Showing search results in a scrollable list that stops at the parent's height and then adds vertical scrolling

I am currently in the process of developing a web application that needs to occupy the entire height and width of the screen using 100vh and 100vw. The main app itself should not have any vertical or horizontal scrolling, but individual components/divs wi ...

Utilizing a JavaScript class method through the onchange attribute triggering

I am facing an issue with a simple class that I have created. I can instantiate it and call the init function without any problems, but I am unable to call another method from the onchange attribute. Below is the code for the class: var ScheduleViewer = ...

Adjusting the display property using the CSS plus symbol operator

I am currently in the process of designing a dropdown menu using CSS. The focus is on utilizing the following code snippet: #submenu_div { display: none; } #li_id:hover + #submenu_div { display: block; } UPDATE: Here is the corrected HTML structure ...

Is there a CSS rule that can alter the appearance of links once they have been clicked on a different webpage?

Just starting out here. Imagine I have 4 distinct links leading to the same webpage - is there a way to modify the properties of the destination page depending on which link was clicked? For instance, clicking on link1 changes the background color of the d ...

Working with both Javascript and jQuery code within a single HTML file

I recently created a website and on one of the pages, I added some jQuery elements like a start button and progress bar. However, when I tried to implement a JavaScript timer on the same page by adding the script into the header, the jQuery elements stoppe ...

The jQuery prop("disabled") function is not operating as expected

Although I've seen this question answered multiple times, none of the suggested solutions seem to be working for my specific example. Hopefully, a fresh set of eyes can help me figure out what's going wrong. Even after adding alerts to confirm t ...

Is there a way to invoke a function using $scope within HTML that has been inserted by a directive in AngularJS?

After moving the following HTML from a controller to a directive, I encountered an issue where the save button no longer functions as expected. I attempted to change the ng-click to a different function within the directive code, and while that worked, I u ...

Tips for expanding an input field to span across two td elements

I am attempting to design a simple form. The issue I am encountering involves creating an input field that spans two td's in the second row of my table. Despite using the colspan="2" attribute within the td tag, the input field does not expand over tw ...