What could be causing the unequal sizes of my flex children?

After some investigation, I have discovered that the issue I'm experiencing only occurs on certain devices, indicating it may be related to the viewport size.

In the code provided, the parent element has a fixed height and width, while the children are supposed to have equal heights.

However, as shown in the screenshot from my laptop below, the demo sometimes displays children of different sizes depending on the parent container's dimensions and the viewing device.

So, how can I ensure that the children always appear with equal heights regardless of the device or the size of the parent container?

Here is an example of the bug

console.clear();
.header {
  height: 200px;
  width: 500px;
  margin: auto;
  display: flex;
}

.flex-container {
  height: 20px;
  width: 20px;
  background-color: black;
  margin: auto;
  display: flex;
  justify-content: space-around;
  align-items: center;
  flex-direction: column;
  transform: scale(5);
}

.child {
  display: block;
  background-color: white;
  height: 10%;
  width: 90%;
}
<div class="header">
  <div class="flex-container">
    <div class="child"></div>
    <div class="child"></div>
    <div class="child"></div>
  </div>
</div>

<script src="https://cdn.tailwindcss.com"></script>

Answer №1

When opting to utilize the flex-box layout, there is no need to specify the width of child elements - simply allow them to expand to full scale. Focus only on setting the height parameter. Additionally, consider adding padding and gaps to the parent container as they synergize well with flex-box design. Below is an example using TailwindCSS (assuming you have already incorporated it into your project), but feel free to customize the styles according to your preferences for optimal performance.

<script src="https://cdn.tailwindcss.com"></script>
<div class="h-screen p-24 bg-slate-900 text-white">
  <!-- flex-container -->
  <div class="w-20 h-20 flex flex-col justify-center items-center gap-4 p-3 bg-slate-700">
    <!-- lines -->
    <div class="w-full h-4 bg-white"></div>
    <div class="w-full h-4 bg-white"></div>
    <div class="w-full h-4 bg-white"></div>
  </div>
</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

Steps for including an animation class in a div

Is it possible to add the sweep to top blue color animation to the red box using a set-timeout function instead of hover? I tried using the following code but it doesn't seem to be working. Can you help me troubleshoot? setTimeout(function() { $( ...

Issue encountered during Heroku deployment: Failed to build React app. When attempting to push changes to Heroku, an unexpected end of input error was received instead of the expected result. This error occurred on an unidentified file at

Encountering a parsing error while attempting to deploy a React app on Heroku using git push heroku master. The app built successfully yesterday, but since then some media queries were added by another contributor to various .scss files. The primary error ...

Is there a discrepancy in the Lodash version number found in the package-lock.json file?

I have upgraded to the latest version of lodash, but in my package-lock.json file it still shows version @4.17.4. Veracode is flagging this as a high risk vulnerability. When I ran npm audit, I received the following message: Invalid: lock file's < ...

Error with HTML form validation

After clicking the "Send Request" button, the query string ?req_flag=0 is not appearing in the URL. What could be causing this issue? I want my URL to look like this: localhost/flavourr/send_req.php?req_flag=0&f_e_mail_add=value <pre> <form ...

Having trouble accessing jQuery function within WordPress

Why is there a ReferenceError: Error message that says "manualEntry is not defined," appearing while trying to use the code snippet below in a Wordpress environment? <a href="#" onclick="manualEntry()">hide</a> <script ...

The art of fluidly positioning elements in Bootstrap columns

My goal is to showcase objects in 3 columns using Bootstrap 4. However, when I implement the code provided, the objects are only displayed in a single column, as shown here: example of 1 column layout. What I actually want is for the objects to be arrange ...

A custom class that uses toggleClass() does not trigger an alert upon a click event

I am encountering an issue with the toggleClass() function in jQuery that I haven't seen addressed before. Despite successfully toggling the class of one button when clicked, I am unable to trigger a click event on the newly toggled class. Here is th ...

When the callback function in the child component is invoked, the state stored in the parent component's useState does not persist

Latest Update After encountering a potential bug with Formik, I decided to switch over to https://react-hook-form.com. It seems that Formik has not received updates in quite some time. If you're interested, you can check out the issue at https://git ...

Upcoming Step 13: Load user preferences and data from localStorage

In my React component within Next.js, I have implemented a tabular structure that saves and restores user's column preferences using localStorage. It is important for the component to load these preferences before displaying any part of the table. Di ...

Adjust the height of the drawer in material-ui

In my current project using react and material-ui, I am facing a simple issue that has me stumped. I am trying to create a drawer with a specific height so that it does not overlap the app bar when opened. Unfortunately, there is no built-in parameter in ...

Issues with Bootstrap indicators and slide controls functionality are being experienced

I am currently exploring a method to create a carousel with thumbnails by referring to this example. I have followed their instructions closely, but unfortunately, clicking on the thumbnails and indicators does not seem to be working as expected. The onl ...

The hamburger menu image is not appearing when using the CSS background-image property

The burger menu image I have as a background image is not displaying in my navigation bar or on the page. I set it to appear when the page is responsive (max-width: 480px), but it still doesn't show. I even tried copying the code to my main CSS above ...

Using Symbol.iterator in Typescript: A step-by-step guide

I have decided to upgrade my old React JavaScript app to React Typescript. While trying to reuse some code that worked perfectly fine in the old app, I encountered errors in TS - this is also my first time using TS. The data type I am exporting is as foll ...

Retrieving data through the google analytics API for analyzing date metrics

I am currently working on extracting individual dates from the data obtained through the Google Analytics API. My goal is to replicate the functionality of the Google Analytics app. For example, in the Google Analytics app, when there is a date range spec ...

Django Media Files Delivery with Nginx (Django/React/Nginx/Docker-Compose)

Background I currently have a one-page web application utilizing the following technology stack: React for the front end Django for the back end Nginx as the web server The web application is dockerized using docker-compose. In this setup, my React app ...

Layer divs on top of each other without explicitly defining their stacking order

I am looking to stack multiple tile divs on top of each other by using negative margin-right: -10px. My goal is to have the previous div displayed on top, with new sibling divs appearing below it. Currently, the newer div overlaps the previous one. While ...

When all y values are zero, Highcharts.js will shift the line to the bottom of the chart

Is there a way to move the 0 line on the y axis to the bottom of the chart when all values are 0? I attempted the solution provided in this post without success. Highcharts: Ensure y-Axis 0 value is at chart bottom http://jsfiddle.net/tZayD/58/ $(functi ...

The panel header is clickable and overlaps with the header buttons

My panel component includes a header with a title and buttons positioned in the right corner. Currently, the downward arrow (chevron) is used to toggle the expansion/minimization of the panel's contents. When I attempt to make the header clickable to ...

Issue with React hook forms and shadcn/ui element's forwardRef functionality

Greetings! I am currently in the process of creating a form using react-hook-form along with the help of shadcn combobox. In this setup, there are two essential files that play crucial roles. category-form.tsx combobox.tsx (This file is utilized within ...

Issue: The module could not be located within the project or in any of the directories, including node_modules

Error: It seems we're having trouble resolving the module navigation/stack-routes from MainTabs.tsx file in gymzoo project directory. The path navigation/stack-routes could not be located within the project or node_modules directory. Greetings! I&apo ...