The expected behavior of flex shrink is not being achieved when the flex direction is set to

After setting the flex-direction to "row", images in a snippet and sandbox shrink as expected. However, changing it to "column" causes the images to not shrink as they should. Attempts to set the height based on other suggestions have been unsuccessful.

To experiment with this issue yourself, modify flex-direction from "row" to "column" in the sandbox. Adjusting the window size will show how the images resize accordingly. When using column, the images end up being 100% width of the parent container. It's puzzling to figure out what's causing this behavior!

CSS:

.container {
  background-color: blue;
  min-width: 0px;
  min-height: 0px;
  max-height: 400px;
  max-width: 400px;
}

.cell {
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
}
.div-item {
  flex: 1 0 50px;
}

.image-pic {
  display: block;
  min-width: 0px;
  min-height: 0px;
  max-width: 100%;
  max-height: 100%;
  object-fit: cover;
  opacity: 0.5;
}

React:

import React from "react";
import "./styles.css";
import { Image } from "react-bootstrap";
import useravatar from "./user.jpg";

export default function App() {
  return (
    <>
      <div className="container">
        <div className="cell">
          <div className="div-item">
            <Image src={useravatar} className="image-pic" />
          </div>
          <div className="div-item">
            <Image src={useravatar} className="image-pic" />
          </div>
          <div className="div-item">
            <Image src={useravatar} className="image-pic" />
          </div>
          <div className="div-item">
            <Image src={useravatar} className="image-pic" />
          </div>
          <div className="div-item">
            <Image src={useravatar} className="image-pic" />
          </div>
          <div className="div-item">
            <Image src={useravatar} className="image-pic" />
          </div>
          <div className="div-item">
            <Image src={useravatar} className="image-pic" />
          </div>
         
         
        </div>
      </div>
    </>
  );
}

Check out the sandbox here:

https://codesandbox.io/s/flex-wrap-with-bootsrap-forked-808gd?file=/src/styles.css

Answer №1

As a newcomer in the field, I may not have all the answers, but here's my take on solving your issue. By setting specific width and height values for the parent div of your image, you can effectively control their size. This method will prevent them from expanding when they wrap around the container. (Additionally, note that while using flex: 1 0 50px, the flex-basis property only accepts values in percentages)

.cell {
  width: 100%;
  display: flex;
  flex:0 0 100%;
  flex-wrap: wrap;
  flex-direction: row;
}
.div-item {
  width:50px;
  height:50px;
}

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

Aligning form fields in a HTML form using Bootstrap

In my extensive form, several fields within the setup encounter the same issue. Specifically, a checkbox below 'contact telephone number' causes the surrounding content to become misaligned. https://i.sstatic.net/8qI8Z.png My attempts to resolv ...

Creating an attention-grabbing alert bar positioned above the menu

When I attempted to add this alert bar to my website, I encountered an issue where it was being hidden behind my menu. Some sources suggest that using z-index and position:absolute can resolve this problem by positioning one element above the other, but th ...

Is it possible to change the Navlink Icon when it's active?

I am currently working on creating a tab bar for a mobile phone using React JS, complete with icons. To manage the routes, I am utilizing React Router. I have successfully implemented changing the color of the icon when it is active by applying an .active ...

Invoking a function prior to the callback function being executed

I am currently developing a to-do app and facing an issue with running a specific function before the callback function returns its output. The callback function is triggered by a click event and displays the user's input value on the screen. However, ...

Ways To Create Multiple HTML Players

After successfully creating an audio player with html, css and javascript, I now face the challenge of adding multiple players to a single page. However, when attempting to play any player besides the first one, it only plays the initial player. How can ...

Change the input field font style in AngularJS

Check out this Plunker link for validation of input field: http://plnkr.co/edit/iFnjcq?p=preview The validation only allows numbers to be entered and automatically adds commas. My query is, if a negative number is entered in the field, how can I change th ...

The functions $.Mustache.load and $.Mustache.render allow you to dynamically load

I have a question regarding my template loading code: $.Mustache.load( "./templates/news/home.tpl" ); The function for loading templates is as follows: function load(url, onComplete) { return $.ajax({ url: url, dataType: opti ...

Is the CSS and jQuery plugin combination blocking the AJAX call or event listener from functioning properly?

After finally getting superfish to work, I encountered a problem where an ajax call would not trigger due to the event listener being prevented. By commenting out the plugin initialization, the event fired but with incorrect data. Any insights on why this ...

Importing Lodash with named imports will bring in the entire bundle

Both of the lines below are contributing equally to the bundle size. import _ from "lodash"; import { get } from "lodash"; I anticipated Line-2 would be smaller in size. ( See image for reference ) Named imports are less costly in An ...

Having trouble with submitting a form using @submit in Vue 3

I am facing an issue with the vuejs @submit.prevent feature in my login form. When I click the login button on my website, it does not work as expected. Even after adding a catch error in the function, the console still shows nothing. Can someone please as ...

What is the most effective method for creating a central file containing multiple subdomain pages?

I am working with a file named master.php, containing a code snippet that retrieves the city and state from the subdomain and inserts it into the body. $url = "//$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; $parsedUrl = parse_url($url); $host = explode(&apo ...

Enhance the collapsible feature in Vue.js by integrating Bootstrap and anim

In the process of creating a side bar menu with collapse show/hide functionality, I am encountering some issues. The current CSS implementation is making the collapse action appear abrupt and unnatural. I am looking to achieve a smooth sliding transition ...

Experiencing trouble with aligning input fields in a Bootstrap layout

When working on a user interface design, I wanted to have different containers with various input type elements. However, I encountered an issue where the datetime picker in one row was not aligning properly with labels above and below it. <div class=" ...

Issue with Bootstrap contact form functionality in PHP not working

I have experience in coding HTML and PHP, but unfortunately, [email protected] (mail address) is still unable to receive emails from my website (http://cloudsblack.info/) and when I click the submit button, it leads to a blank page (http://cloudsblack.info ...

Leveraging Material UI's Button element along with the enctype attribute

I'm working on incorporating Multer for image uploads and utilizing Material UI's button component with the onClick prop to submit the data. If I wrap the button component within a form tag, will it achieve the same result? If not, how can I spec ...

HTML/CSS - Troubleshooting Animation Issues

I am currently experimenting with different website animations and implementing responsive design. However, I encountered an issue when trying to apply these changes to my header, which also affects the .heading element. It seems that there is a problem w ...

Handling overflow and z-index of tabs in Vuetify Drawer

Struggling to create an expandable sidebar menu using Vuetify2, following the documentation, but unable to prevent the expanded menu from overlapping other elements on the page. The current behavior causes items to be pushed away and wrap onto the next ro ...

What is preventing the nativeEvent callback from being triggered in React Native's Animated.event() function?

Why isn't the nativeEvent callback triggering in my Animated.event call when dragging a box? I am working on implementing functionality to prevent draggable components from going off-screen using gesture control. However, I'm facing an issue whe ...

How can you transfer the selected options value from a select menu to a button's onclick event in

Is it possible to pass the value of select-options, but then change the approach and pass the value first on the button for onClick function? Thank you! import { useSelector, useDispatch } from "react-redux"; const Purchase = () => { const products ...

Utilizing Two Buttons with Distinct Functions Within a PHP Webpage

My PHP page includes two buttons: Save and Submit. The Save button is used for saving form data, while the Submit button is used for submitting the final data. <button id="save" name="save" onclick="saveForm();">Save</button> <button id="s ...