Why is a div nested inside an overflow: hidden; div not expanding to the full width of its content?

.container {
  white-space: nowrap;
  overflow: hidden;
}

.inner {
  width: 100%;
}
.list-item {
  display: 'inline-block',
  boxSizing: 'border-box',
  border: '3px solid black'
}



import React, { Component } from 'react'



function calcItemWidth(width, tiles) {
  return width / tiles
}

export class Container extends Component {
  constructor() {
    super(...arguments);

  }

  get containerSize() {
    return document.querySelector('.container').clientWidth;
  }

  componentDidMount() {
    const itemwidth = calcItemWidth(this.containerSize, 2)

    const listItems = document.querySelectorAll('.list-item');
    Array.from(listItems)
      .map(item => {
        item.style.width = `400px`; 
      })
  }

  renderChildren() {
    return this.props.children.map(
      (child, index) => (
         <li key={child.key} data-index={index} className="list-item" style={listItem}>
          {child}
        </li>
      )
    )
  }

  render() {
    return (
       <div className="container">
        {this.renderChildren()}
      </div>
    )
  }
}

export default Container

In my component called Container, I have set a fixed width of 800px and applied overflow: hidden. Inside the Container, there is an element named inner, which should expand to the total width of its children. For example, if there are 4 listItems, the inner should be 1600px wide.

I have attempted to set the width of inner to width: 100% and min-width: 100%, but it does not adjust to the width of its children. How can I make the inner element expand beyond the width of the container?

UPDATE: The overflow of the inner element does not need to be visible or have a scroll bar. It simply needs to match the combined width of its children elements.

Answer №1

Include display: inline-block; within the inner class

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

Achieving a seamless integration of a navbar and video in Bootstrap 5.3: tips and tricks

I'm updating a website design using Bootstrap and I want to create a navbar with a video playing in the background. To ensure that the navbar stays fixed at the top while scrolling, I made it sticky. After testing various methods, I managed to posit ...

When creating a list of children in a React app, make sure to assign each child a unique "key" prop for proper rendering

Currently, I am in the process of developing a React Notes application with an API integration. While most functionalities are working flawlessly, I encountered a warning message upon adding a new note: Each child in a list should have a unique "key&q ...

Monochrome tabletop solid in one hue

I'm trying to eliminate the space between the columns in my table so it looks solid. Here's the CSS style I've been using: <style> tr, th, td {margin:0;padding:0;border:0;outline:0;font-size:90%;background:transparent;} table{ margin: ...

Just a straightforward Minimum Working Example, encountering a TypeScript error TS2322 that states the object is not compatible with the type 'IntrinsicAttributes & Props & { children?: ReactNode; }'

Currently, I am immersed in a project involving React and Typescript. I am grappling with error code TS2322 and attempting to resolve it. Error: Type '{ submissionsArray: SubmissionProps[]; }' is not assignable to type 'IntrinsicAttributes ...

Begin the Material UI Datepicker from the first day of the upcoming month

I'm trying to see if it's possible to set the default current date of a material-UI picker to the first day of next month, but I haven't been able to find any information on how to do this. Can anyone confirm if there is an option for that? ...

The hyperlink appears to be malfunctioning with an additional border surrounding it within a pop-up window

I am facing an issue with a link <a> not functioning properly with a popup dialog on . Additionally, there seems to be a border that appears around the <a> when the popup initially displays. If you click on "Leer más" for any product, you can ...

Adjusting the height of a SelectField in ReactJS with MaterialUI

I have incorporated the React material-ui SelectField component into my webpage. Unfortunately, I am facing difficulty in adjusting the height of the select field. Below is a snippet of my code: <SelectField underlineStyle={{ display: 'none&a ...

"Encountering a RangeError with Node.js Sequelize while working with

I need some assistance with using Sequelize in my Node.js application paired with MySQL. When I try to execute the command npx sequelize db:create, I encounter an error that I do not know how to resolve. Any guidance on this matter would be greatly appreci ...

How can audio be efficiently streamed to the browser in small chunks using JavaScript?

I am currently working on setting up an internet radio station where I want to easily switch songs and overlay sounds. My goal is to limit the audio rate so that the feed can be adjusted before being sent out. Additionally, I would like to provide continuo ...

What is the best way to encapsulate a slider within a fragment to prevent the occurrence of the "Type 'Element[]' is not assignable to type 'ReactNode'" error?

I'm encountering an issue with a Slider component in a NextJs landing page template. Every time I try to map through an array within the Slider component, I receive an error. I've attempted to find solutions online and came across this related th ...

What seems to be the issue with this Discord.js kick command code? It's not

Okay, so I'm in the process of creating a kick command for my Discord bot. The issue I'm encountering is that when no reason is specified or if a user is not mentioned to be kicked, the bot responds correctly but does not actually kick the user. ...

Setting state for a dynamic component based on condition in React

Working on creating a dynamic component where the data index matches the URL parameter blogID received from the router. Below are the router parameters sending props to the component: <Route path='/blog/:blogId/:blogTitle' render={() => & ...

Dealing with AngularJS: Overcoming Lexer Errors When Passing Email Addresses for Regex Validation in Functions

Trying to pass an email address to an AngularJS function has been my recent challenge. Below is a snippet of the code I've been working on. <script> //For simplicity, descriptions for the module and service have been omitted this.sendEmail = f ...

The issue with Jquery Lightbox/Modal doubling upon clicking

Having just started with jQuery, I've encountered an issue with my Gallery Lightbox/Modal. Whenever I click on a thumbnail, the modal reopens itself and I'm unsure where to set a reset. Any help would be greatly appreciated. jQuery(function($) { ...

Issue with D3: Events not triggering transitions

I am currently working on creating a bar chart using D3 in Angular4. // Enter Phase this.chart.selectAll('.bar') .data(this.barData) .enter() .append('rect') .attr('class', 'bar'); // Update Phase let bars ...

Are node.js and AngularJS connected in any way?

Node.js relies on npm for package management, while AngularJS CLI also uses npm for its modules. Is there a connection between these two? I have installed Node.js and tested it with a simple 'hello.js' file containing just one line of code: con ...

Reset the form value in React using Material UI components

Currently, I am working with React Material and hooks, attempting to reset a material form. However, despite my efforts to adjust the state, I am not seeing any changes reflected. <form className="create-account-form" autoComplete="off" onSubmit={onSub ...

Sending a file to the jqGrid handler

Currently, I am using Grails in combination with jqGrid and attempting to implement a rather unique feature. My goal is to allow users to upload a file which will then be sent to the jqGrid controller and used as a filter for the data displayed on the grid ...

Getting a Cookie in React from an Express JS API (MERN Stack)

My API in Express JS stores a token in a cookie on the client-side (React). The cookie is generated only when a user logs into the site. When testing the login API with Postman, the cookie is generated as expected: https://i.sstatic.net/rL6Aa.png However ...

Executing numerous xhttp.send requests within a single webpage

Hey there, I'm facing an issue with xhttp.send(); as it keeps giving me the error message net::ERR_EMPTY_RESPONSE Here is a snippet of my code. Whenever a user clicks too quickly, they get kicked off the page. Is there a way to prevent this? docum ...