1

How do I get the input box to be vertically aligned to the middle? I tried adding vertical-align: "middle" to a few places but I am not getting any success. I feel like flexbox is a part of the problem here?

.container {
  /* Flex Properties */
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  align-items: center;
}

.item {
  background-color: orange;
}

label {
  width: 100px;
  display: inline-block;
}
<div class="container">
  <div class="item">
    <label>Gee my iefwaf fwats: </label>
    <input>
  </div>
</div>
VXp
  • 11,598
  • 6
  • 31
  • 46
Frank
  • 2,109
  • 7
  • 25
  • 48

3 Answers3

5

Give the .item div display: flex and align-items: center, since it's the parent of the input element:

.container {
  /* Flex Properties */
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  align-items: center;
}

.item {
  display: flex; /* added */
  align-items: center; /* added */
  background-color: orange;
}

label {
  width: 100px;
  /*display: inline-block; not necessary*/
}
<div class="container">
  <div class="item">
    <label>Gee my iefwaf fwats: </label>
    <input type="text">
  </div>
</div>
VXp
  • 11,598
  • 6
  • 31
  • 46
1

Try this css code with your html.

.container {
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  align-items: center;
}

.item {
  background-color: orange;
  display: flex;
  align-items: center;
}

label {
  width: 100px;
  display: inline-block;
}
input {
  display: inline-block;
}
Aryan Twanju
  • 2,464
  • 1
  • 9
  • 12
0

Please check with the added CSS::

.container {
  /* Flex Properties */
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  align-items: center;
}

.item {
  background-color: orange;
}

    label {
      width: 100px;
      display: inline-block;
      vertical-align: middle;
    }

input {
      width: 100px;
      display: inline-block;
      vertical-align: middle;
    }
<div class="container">
  <div class="item">
    <label>Gee my iefwaf fwats: </label>
    <input>
  </div>
</div>
Sonia
  • 1,909
  • 1
  • 11
  • 13