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
  • 10,960
  • 6
  • 31
  • 42
Frank
  • 1,831
  • 5
  • 16
  • 40

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
  • 10,960
  • 6
  • 31
  • 42
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,444
  • 1
  • 8
  • 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,839
  • 1
  • 11
  • 13