HTML
<div class="combobox">
<input type="text" value="" name="brand" class="text" id="brand"><span class="dropdown_btn"></span>
</div>
CSS
.combobox {
margin: 0;
padding: 0;
vertical-align: middle;
}
.combobox input {
height: 20px;
line-height: 20px;
margin: 0;
padding: 0;
}
.combobox .dropdown_btn {
width: 18px;
height: 20px;
margin-left: -20px;
display: inline-block;
cursor: pointer;
background-color: blue;
}
但它是这样的:
我不知道差距来自哪里;为什么文本输入不像蓝色按钮那样紧贴其容器div?
答案 0 :(得分:4)
尝试将vertical-align: middle;
添加到.combobox .dropdown_btn
并将其从combobox
类中删除:
.combobox .dropdown_btn {
width: 18px;
height: 20px;
margin-left: -20px;
display: inline-block;
cursor: pointer;
background-color: blue;
vertical-align: middle;
}
答案 1 :(得分:3)
您需要将vertical-align: middle
应用于内联元素:
.combobox {
margin: 0;
padding: 0;
}
.combobox input {
height: 20px;
line-height: 20px;
margin: 0;
padding: 0;
vertical-align: middle;
}
.combobox .dropdown_btn {
width: 18px;
height: 20px;
margin-left: -20px;
display: inline-block;
cursor: pointer;
background-color: blue;
vertical-align: middle;
}
请参阅:JSFiddle
vertical-align
属性不会被继承,因此您需要将其指定给要调整的任何内联元素。
答案 2 :(得分:3)
尝试将vertical-align:top
设置为input
.combobox {
margin: 0;
padding: 0;
}
.combobox input {
margin: 0;
padding: 0;
height: 20px;
vertical-align: top;
}
.combobox .dropdown_btn {
width: 20px;
height: 24px;
margin-left: -20px;
display: inline-block;
cursor: pointer;
background-color: blue;
}
<div class="combobox"><input type="text" value="" name="brand" class="text" id="brand"><span class="dropdown_btn"></span></div>
答案 3 :(得分:0)
.combobox .dropdown_btn {
width: 18px;
height: 20px;
margin-left: -20px;
display: inline-block;
cursor: pointer;
background-color: blue;
vertical-align: middle;
}