Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

347
Views
css - how to make all flex items to have equal height and width but not using fixed value of height and weight

I have 3 flex items here, but the width of 2nd item is larger than others, since the description of 2nd item is very long. enter image description here

Is it possible to make all flex items to have equal height and width but not using fixed value of height and weight, when the content of description changes.

App.js

import "./styles.css";

export default function App() {
  const containerStyles = {
    display: "flex",
    flexDirection: "column",
    backgroundColor: "green",
    marginRight: "10px",
    flex: 1
  };

  return (
    <div style={{ display: "flex" }}>
      <div style={containerStyles}>
        <div>Title 1</div>
        <div>Description 1</div>
        <div>Click to view detail</div>
      </div>
      <div style={containerStyles}>
        <div>Title 2</div>
        <div>Description 2 veryyyy longgggggggggggggggggggggg</div>
        <div>Click to view detail</div>
      </div>
      <div style={containerStyles}>
        <div>Title 3</div>
        <div>Description 3</div>
        <div>Click to view detail</div>
      </div>
    </div>
  );
}

Codesandbox
https://codesandbox.io/s/crazy-cookies-nw0ykj

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

The middle box is big because of a unbreakable word longgggggg.... If you overflow it to the next line, things are going to work fine for you. Setting the overflow-wrap property to anywhere should work.

Try setting it for the flex container

  const containerStyles = {
    display: "flex",
    flexDirection: "column",
    backgroundColor: "green",
    marginRight: "10px",
    flex: 1,
    overflowWrap: 'anywhere',
  };

So you can see the text being cut in order to respect the width of the container so that you have equal width and height.

After applying overflow

about 4 years ago · Santiago Trujillo Report

0

Since I forgot you need the same width as well, I've modified my answer.

In your case, use both justify-content: space-between to made the child element height inside flexbox looks like equal, and overflow-wrap: anywhere to let the longer text to be wrapped to made flex items have same width.

enter image description here enter image description here

about 4 years ago · Santiago Trujillo Report

0

Your long word is what's breaking it. You need to set overflow to anything other than visible. You can also add in the word-wrap property to keep everything visible.

const containerStyles = {
    display: "flex",
    flexDirection: "column",
    backgroundColor: "green",
    marginRight: "10px",
    flex: 1,
    "word-wrap": "break-word",
    overflow: "hidden"
  };
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!