How to properly size a child div inside a parent container

I'm having trouble with sizing a child div inside a parent div. The problem is that the child div's size changes according to the number of elements it contains, but I want all the child divs to be the same size regardless. This issue arises within the .container element. When my array returns 6 items, everything works fine. However, if the array has less than 6 items, each {styles.object} gets resized based on the available space in the container. Typically, when fewer than 6 items are returned, each item becomes larger and takes up more space. But I need all the objects to be the same size even if there are less than 6 items.

    var textContainer = <div className={styles.text_container}>
    <div className = {styles.text}>Experts</div>
    <span className={styles.view}onClick={() => handleNextClick()} >View More</span>
    </div>
    var displayData = <div className = {styles.container}>
            {array.slice(0,6).map((item,i)=>{
                return (
                    <>
                        <div className ={styles.object} key={i}>
                            <img className ={styles.img} src={item.image}></img>
                            <div className={styles.name}>{item.name}</div> 
                        </div>
                    </>
                )
            })}
</div>
return (
<>  
    {textContainer}
    {displayData}
</>

.text_container{
    display: flex;
    margin: 50px;
    margin-left: 150px;
    margin-bottom: 10px;
    width: 80vw;
    height: 3vh;
    padding: 0;
    align-items: center;
}
.text {
    display: inline;
    font-size: 20px;
    font: url('../../public/fonts/Lato-Bold.ttf');
    letter-spacing: 0.24px;
    flex: 1;
}
.view{
    display: flex;
    font-size: 14px;
    font: url('../../public/fonts/Lato-Bold.ttf');
    cursor: pointer;
}
.container{
    display: flex;
    margin: 50px;
    margin-left: 150px;
    padding: 0;
    width: 80vw;
    height: 28vh;
    justify-content: flex-start;
}

.object{
    display: flex;
    margin-right: 30px;
    width: 22vw;
    height: 25vh;
    position: relative;
}
.name{
    margin-top: 0;
    font-size: 14px;
    width: 100%;
    position: absolute;
    top: 102%;
    text-align: center;
}
.img{
    width: 100%;
    height: 100%;
    border-radius: 50%;
    cursor: pointer;
}

Answer №1

To optimize the layout, consider setting both a minimum and maximum width for the child elements

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

Seeking an improved approach to invoking a React component based on varying states. Open to suggestions for a more effective

I am currently working with a Modal Component from Material UI and my goal is to conditionally render this component based on the state provided by useState. This is what I have done so far - <ModalPopup open={deleteRole} onClose={handleDeleteClo ...

One method of extracting an object from an array using a parameter function is by utilizing the following approach

I am searching for a specific object in an array based on the user-provided ID. var laptops = [{ "name": "Firefox", "age": 30, "id": "ab" }, { "name": "Google", "age": 35, "id": "cd", "date": "00.02.1990" }, { "na ...

Angular 4 - The Promising Outcome: How to Retrieve the Value upon Completion

Is there a way to retrieve a value from a promise and store it in a global variable? I've been attempting to accomplish this, but the global variable remains undefined. import { Injectable } from '@angular/core'; import {ActivatedRouteSnap ...

Is your React conditional rendering malfunctioning due to state issues?

I am attempting to create a component that will only be displayed after clicking on a search button. Below is the current code that I have: Update After making some changes, I am now encountering this error: Error: ERROR in /home/holborn/Documents/Work ...

Overlapping Bootstrap cards conundrum

Does anyone know how to align Bootstrap cards and make them responsive? I have them centered, but they are overlapping and sticking to the left side. This is for email development with a maximum width of 680px. Any assistance would be greatly appreciated! ...

The modals equipped with data-dismiss="modal" and data-target="#id" do not navigate to their intended destination

Attempting to focus the input field using the modal data-target function on button click. The input field is focused, but a div called <div class="modal-backdrop in"> is created and the modal does not close properly. This prevents the user from click ...

How can I use variables to show the second dropdown list only when a value has been selected in the first dropdown?

Is there any way I can choose a specific value from a dropdown list and based on that selection, show another dropdown list? I understand how to do it with regular words, but what if I use variable names? University Name: <select name="university" id=" ...

Expect a promise to be resolved in the RootCtrl of Angular using $http

One of the functions in my RootCtrl is responsible for calling an http api and returning the result. $scope.checkAccess = function(){ var result = MyService.me(); result.then(function(response){ console.log(response); if (response. ...

"Utilizing multiple class names in Next.js to enhance website styling

Looking for a way to apply multiple classNames in Next.js, especially when dealing with variable classnames? I'm following the component level CSS approach. Take a look at my code and what I aim to achieve: import styles from "./ColorGroup.mod ...

A guide on organizing and categorizing data by name with angularjs

Presented here is a list of descriptions associated with specific names. I am seeking guidance on how to group or list the descriptions by name. html: <body ng-app="app" ng-controller="MainCtrl"> <div ng-repeat="nameGroup in loopData"> & ...

The webpage at 'https://abcd.ac.in/' has been declined to be displayed in a frame due to the 'X-Frame-Options' being set to 'sameorigin'

When attempting to load a website within an iframe, I encountered an error in the console stating "Refused to display 'https://abcd.ac.in/' in a frame because it set 'X-Frame-Options' to 'sameorigin'. Despite trying other alte ...

Is it possible to customize the CSS styles of a jQuery UI modal dialog box?

Having trouble with my CSS styles not applying to a dialog modal added to my website using jQuery UI, even when using '!important'. I suspect that the predefined jQuery or UI CSS styles from a CDN link are preventing me from overriding them. The ...

Uncovering a Memory Leak in a ReactJS App

As a newcomer to this framework, I know this question may be repetitive, but I am eager to troubleshoot and resolve the issue in my project. Every page of my project is showing a memory leak warning, and I have been learning about CRUD operations through Y ...

Circular center button in the footer UI

Struggling with aligning a button in the footer perfectly? I have two icons on each side and while the UI is almost there, something seems off with the center icon's padding and shadow. I'm currently working with material-ui. Take a look at the i ...

What are the methods to determine if vue-router is being utilized within the present Vue instance?

I am working on creating a library that includes a vue.js component with navigation elements. The goal is for this component to be flexible, able to function both with and without vue router. When used with the router, it will utilize <router-link> ...

The default clearIcon in MUI Autocomplete getting overridden by the endAdornment

I have integrated an MUI Autocomplete with a loading spinner as an endAdornment in the Textfield while fetching options from an external source. However, this seems to be removing MUI's default clearIcon (likely because it is also considered an endAdo ...

Nuxt - issue with updating window innerwidth getter

The class based components in our project utilize a getter to retrieve the window innerWidth. However, I've noticed that the value is only set once and doesn't update if the window width changes. get viewPortWidth() { if (process.client) { ...

Is there logic in developing a web application using a combination of a NestJS backend and Next.js frontend, along with authentication features?

Currently, I am embarking on the journey of developing a web application using React and Next.js. With my previous experience in backend development using NestJS, I decided to integrate it into this project as well. However, I am unsure if separating the f ...

Passing the final element of a POST array to a different page

I am having trouble retrieving the correct array values from the form. In my code, I am invoking the form option value 3 times, which is defined in the database. Here is an example of what is currently in the database: https://i.sstatic.net/G4JQx.png Wh ...

I require a modification in the style of every anchor element found within a div containing the designated class

In a div with the class fview, there is a nested element called iNside which contains a span. Additionally, there are anchor elements within another span, ul li, and another div, among others. I want all anchor elements to have the same style. I tried app ...