1

I am trying to create something similar to a table with rows and cells, but I don't want to use rows and cells, I am currently using DIV elements and everything is going smooth until I try to adjust the width of the inner DIV elements to fill the width of their parent DIV (which would be the row) without having to do exact calculations for the percentage needed.

.container {
    width: 100%;
    display: flex;
    border: 5px solid black;
}

.container > div {
    width: inherit;
    display: inline-flex;
    border: 5px solid red;
}

.container > div > div {
    border: 5px solid green;
    height: 50px
}
<div class="container">
  <div>
    <div>
      <span>TEST</span>
    </div>
    <div>
      <span>TEST</span>
    </div>
  </div>
</div>
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701

4 Answers4

1

From MDN:

The flex CSS property is a shorthand property specifying the ability of a flex item to alter its dimensions to fill available space.

You need to provide flex: 1; to .container > div > div to expand the inner div elements.

.container > div > div {
    border: 5px solid green;
    height: 50px
}

Demo

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
0

You can use the flex property:

.container {
  width: 100%;
  display: flex;
  border: 5px solid black;
}

.container>div {
  width: inherit;
  display: inline-flex;
  border: 5px solid red;
}

.container>div>div {
  border: 5px solid green;
  height: 50px;
  flex: 1;
}
<div class="container">
  <div>
    <div>
      <span>TEST</span>
    </div>
    <div>
      <span>TEST</span>
    </div>
  </div>
</div>
sol
  • 22,311
  • 6
  • 42
  • 59
0

perhaps this is what you need? (innermost div should inherit width too)

.container {
    width: 100%;
    display: flex;
    border: 5px solid black;
}

.container > div {
    width: inherit;
    display: inline-flex;
    border: 5px solid red;
}

.container > div > div {
    width: inherit;
    border: 5px solid green;
    height: 50px
}
<div class="container">
  <div>
    <div>
      <span>TEST</span>
    </div>
    <div>
      <span>TEST</span>
    </div>
  </div>
</div>
0

Here i make a change on your CSS but you need to do a flex when you try to autogrow your divs. Look at the .container > div > div styling.

.container {
    width: 100%;
    display: flex;
    border: 5px solid black;
}

.container > div {
    width: inherit;
    display: inline-flex;
    border: 5px solid red;
    
    
}

.container > div > div {
    border: 5px solid green;
    height: 50px;
    flex: 1;
}
<div class="container">
  <div>
    <div>
      <span>TEST</span>
    </div>
    <div>
      <span>TEST</span>
    </div>
  </div>
</div>
dutchsociety
  • 575
  • 4
  • 22