如何让输入框与中间垂直对齐?我尝试添加vertical-align:" middle"到几个地方,但我没有取得任何成功。我觉得flexbox是问题的一部分吗?
.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>
&#13;
答案 0 :(得分:4)
提供.item
div display: flex
和align-items: center
,因为它是input
父 >元素:
.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>
答案 1 :(得分:1)
使用您的html尝试此css代码。
.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;
}
答案 2 :(得分:0)
请查看添加的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>