1

it seems like i didn't understand the flexbox right.

But i think the with of a div in a flexboxitem is ignored.

Like in this fiddle: https://jsfiddle.net/34f9awsk/6/

CSS:

.wrapper {
  width: 200px;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  flex-direction: row;
}

.ele {
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  flex-direction: row;
  flex: 3;
}

.ele1 {
  flex: 1;
}

.ele input {
  display: inline;
  max-width: 100%;
}

HTML:

<div class="wrapper">
  <div class="ele ele3" style="background-color: red;">
    <input type="number" size="4" value="9999" />
  </div>
  <div class="ele ele1" style="background-color: green;">
    2
  </div>
  <div class="ele ele3" style="background-color: yellow;">
    <input type="number" size="4" value="9999" />
  </div>
</div>

Can you help me to fix it?

Thank you!

Asons
  • 84,923
  • 12
  • 110
  • 165
Flo
  • 1,179
  • 3
  • 15
  • 43

1 Answers1

6

Flexbox items has a min-width that defaults to auto, which means they won't shrink below their contents width.

In this case your input element has a default width set in the user agent style sheet, which then dictate the size of the flex item.

Give the ele a min-width: 0 and it will work as expected.

.wrapper {
  width: 200px;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  flex-direction: row;
}

.ele {
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  flex-direction: row;
  flex: 3;
  min-width: 0;
}

.ele1 {
  flex: 1;
}

.ele input {
  display: inline;
  max-width: 100%;
}
<div class="wrapper">
  <div class="ele ele3" style="background-color: red;">
    <input type="number" value="9999" />
  </div>
  <div class="ele ele1" style="background-color: green;">
    2
  </div>
  <div class="ele ele3" style="background-color: yellow;">
    <input type="number" value="9999" />
  </div>
</div>
Asons
  • 84,923
  • 12
  • 110
  • 165
  • Thank you! That helped me! But now i want a "€" after the input and this isn't also not working. Please a look here: https://jsfiddle.net/34f9awsk/10/ – Flo Jul 04 '17 at 13:43
  • @Flo If it helped an upvote/accept would be appreciated. Regarding the "€", I will take a look later and suggest a solution. – Asons Jul 04 '17 at 15:11