I seem to be having a problem with CSS and Flexbox sizing. Does anyone have an explanation for what might be

Hey there! I'm currently in the process of building a Netflix clone, and everything seems to be working well except for one issue with the layout. No matter how I adjust the width of the div containing the images, they just won't change size. I've checked the console and can't seem to find any rule that might be causing this problem. I've tried setting the images to 100% width of their parent container, but that just makes them appear tiny.

CSS has always been a bit tricky for me because it doesn't provide immediate feedback like a console would. If anyone could take a look at the code below and help me understand what's going wrong, I'd really appreciate it. (Also, does anyone know how long it takes to stop feeling clueless when working with CSS?)

I've included the relevant code snippet below. The row__imgLarge class is specifically applied to a single row, which is experiencing the same sizing issue as the rest.

<div className="row__images">
    {movies.map((movie) => (
      <div
        className={`row__imgContainer  ${
          isLargeRow ? "row__imgLarge" : ""
        }`}
        key={movie.id}
        onClick={() => handleClick(movie)}
      >
        <img
          className="row__image"
          src={`${base_url}/${
            isLargeRow || !movie.backdrop_path
              ? movie.poster_path
              : movie.backdrop_path
          }`}
          alt={movie?.title || movie?.name || movie?.original_name}
        />
      </div>
    ))}

.row__images {
  display: flex;
  overflow-y: hidden;
  overflow-x: scroll;
  padding: 20px;
}

.row__imgContainer {
  /* width: 15.8vw; */
  max-height: 40vh;
  width: 150vw;
  margin-right: 0.6vw;
}

.row__image {
  width: 100%;
  transition: transfrom 440ms;
}

.row__imgLarge {
  max-height: 40vh;
}

Answer №1

When working with flex items within a flex container, their widths are determined by the container itself. To control the width of these items, you will need to use various flex properties. Take a look at the justify-content property on the container, as well as the flex-grow, flex-shrink, and flex-basis properties on the individual items.

If you wish for the items to maintain a specific, unchanging width, you can achieve this by setting both the grow and shrink properties to 0, and specifying the desired width using the basis property:

.row_imgContainer {
  flex-grow: 0; /* do not allow growth */
  flex-shrink: 0; /* prevent shrinking */
  flex-basis: 200px; /* set desired width */
}

.row_imgContainer {
  flex: 0 0 200px; /* shorthand version of above */
}

To create a row of images that scrolls horizontally, set overflow: auto (or scroll) on the flex container and ensure the items do not shrink:

.container {
  display: flex;
  overflow-x: auto;
  max-width: 500px;
}

.container>* {
  flex: 0 0 200px;
}
<div class="container">
  <img src="//placekitten.com/200" />
  <img src="//placekitten.com/201" />
  <img src="//placekitten.com/200" />
  <img src="//placekitten.com/199" />
  <img src="//placekitten.com/200" />
  <img src="//placekitten.com/202" />
  <img src="//placekitten.com/204" />
</div>

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

The expression "const io = require('socket.io')" cannot be invoked as a function

This is my index.js file running on the server side const express = require('express'); const app = express(); const server = require('http').createServer(app); const PORT = process.env.PORT || 5000; const router = require('./rou ...

How can you access additional fields beyond what is displayed in a dropdown select menu in React?

I am working with an array of Jsons that contain the fields ID, name, and description. My goal is to create a dropdown selection box that will show both the name and description when clicked, and then store the associated ID in the rawID state. I have been ...

The Mystery of jQuery Isotope Plugin: Why Can't I Add "display:none" Inline?

I'm currently in the process of integrating Isotope into my latest Wordpress theme. However, I've encountered an issue where it's not appearing on the page due to some external factor adding an inline style (display:none) to the main isotope ...

Customize Color of Bootstrap Tooltips

Is there a way to customize the appearance of BootStrap tooltips by changing the color and aligning the text to the left? I've tried various CSS modifications from different posts, but none seem to work. Any idea on how to alter the CSS of the tooltip ...

What is the best way to ensure a grid element has a column designated for each of its children?

Imagine this HTML structure: /* Desired styling: */ .container { display: grid; grid-template-columns: 250px 250px 250px /* this is the part to automate */ grid-template-rows: 50px; } .child { width: 100%; height: 100%; background: ...

Creating a personalized cover for devextreme column in datagrid: A Step-by-Step Guide

I have encountered an issue with wrapping a Column inside my DataGrid. My goal is to create a customized component that generates a Column with the correct formatting. For instance, I want to develop a ColumnDate component that includes specific date forma ...

What is the best way to position the div element to the right side of the webpage?

Looking at my HTML code below, I am trying to reposition the 'site-logo' and 'nav-search-wrapper' div elements to the left side of the parent div (top-nav) and have the 'list' div element appear on the right side. However, the ...

The combination of Reactflow and Next.js with the app router is causing nodes and edges to not appear on

Recently, I attempted to implement a basic example using "reactflow" with versions "11.8.3" and "next": "13.4.19". I utilized the app router of next.js for this purpose. To my dismay, the nodes and edges failed to render and the corresponding html elements ...

Navigation website with a twist

My design features a main navigation that is rotated 90 degrees, while the sub-menu remains horizontally aligned. <div id="nav"> <ul> <li><a href="#">Woonaccessoires</a></li> ...

Create a toggle effect using attribute selectors in CSS and JavaScript

I am looking to switch the "fill: #000;" from the CSS property "svg [id^='_']". Usually, I would use a method like this, but it seems that I can't do so because "svg [id^='_']" is not an element, correct? pub.toggleClass = functi ...

AutoComplete is failing to properly implement the value assigned via setState

Currently, I am utilizing the Autocomplete feature from Material-UI version 5.11.6, and encountering an issue while attempting to assign a value via setState. I have included a demonstration in a sandbox environment to showcase the problem here. Even thoug ...

What is the process for deconstructing errors from the RTK Query Mutation Hook?

Currently, I am utilizing redux toolkit query for handling my data fetching API. One issue that I have encountered is with error handling. When an error is returned from the server, it comes in as an object with nested data. However, when trying to access ...

Preventing Page Content Overflow in Semantic-ui SideNav

I am currently working on a webpage that includes a side navigation bar. I recently started using semantic-ui and its grid system, but I'm facing an issue where the content of the page flows under the side nav and gets hidden. I have tried various sol ...

Creating a dynamic sidebar navigation that adapts seamlessly across all devices, including desktop and mobile platforms

I am currently using Bootstrap 5 to design a resume webpage. While I have achieved the desired look, I am facing an issue with making the sidebar fixed without overlapping other content when the page is resized to be smaller. Initially, I attempted to use ...

Swap out the content in a text input box with the text chosen from a suggested autocomplete option

I am working on a text input box with auto-complete options displayed below it. I want to enable users to navigate through the options using keyboard arrows and "select" one, causing it to change color. How can I update the text in the input box with the s ...

Is there a way to implement fixed scrolling on a website?

I'm interested in implementing fixed scrolling on a webpage similar to the effect used here: . When you scroll on that website, it smoothly transitions to the next div. I believe there is some JavaScript involved, but I am not sure how to achieve thi ...

Discovering the capabilities of heic2any in a Next.js client-side environment

Here is the code snippet: import convert from 'heic2any' try { convertedImage = await convert({ blob: propsAndFile?.file }) } catch (error) { console.error(error) } Encountered an error while trying to run this code on the client side, ...

Place a "sticky" button directly below a second "sticky" navigation bar

Within my app file, I have customized components like an appbar and various page elements: const styles = theme => ({ appBar: { width:'100%', }, }); class App extends Component { render() { const {classes} = this.props; ...

Creating a centered transparent rectangle of a specific width using HTML

I am working on a page layout similar to this FIDDLE body { margin:0 auto; max-width: 800px; padding:0 0 0 0; text-align:left; background-color:#FFFFFF; background-image: url('http://freeseamlesstextures.com/images/40-dirty-pa ...

MUI Textfield displaying multiple lines based on state change (when focus is removed)

Currently, I'm working on a problem where I need to enable multi-line input after clicking on it (by default it is set to single line). I have implemented a state that switches to true when the onFocus event occurs (and back to false on onBlur event). ...