-1

Suppose, I have 3 divs A, B and C inside a div which is a flex.

[ABC....]

I want to distribute remaining space only between B and C i.e. I want to achieve this

[AB....C]

Is there some property that helps me specify to distribute space between B and C, or in other words make B stack with A?

Note: I want to do this without any div nesting.

Thank you.

uttamkhanal
  • 145
  • 2
  • 9

2 Answers2

0

Add an empty element with a high flex-grow value. This will consume the available space.

#list {
  display: flex;
  list-style-type: none;
  padding: 0;
  margin: 0;
}
li {
  border: 1px dotted currentColor;
  padding: 8px;
}
.spacer {
  flex-grow: 100;
}
<ul id="list">
  <li>A</li>
  <li>B</li>
  <li class="spacer"></li>
  <li>C</li>
</ul>
Niet the Dark Absol
  • 311,322
  • 76
  • 447
  • 566
0

Simply use margin and auto value like this with no need to add extra markup:

#list {
  display: flex;
  list-style-type: none;
  padding: 0;
  margin: 0;
}
li {
  border: 1px solid;
  padding: 8px;
}
li:last-child {
  margin-left:auto;
}
<ul id="list">
  <li>A</li>
  <li>B</li>
  <li>C</li>
</ul>
Temani Afif
  • 211,628
  • 17
  • 234
  • 311