Html 垂直对齐中心输入和div中的按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10850341/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:47:36 来源:igfitidea点击:
vertical align center input and button in div
提问by Jizbo Jonez
I have a search setup inside a div but for some reason cannot get it to vertically align center
我在 div 中有一个搜索设置,但由于某种原因无法使其垂直居中对齐
This is my code -
这是我的代码 -
HTML:
HTML:
<div class="search">
<input class="searchfield" type="text" placeholder="Search..." value="" /> <button class="searchbutton">SEARCH</button>
</div>
CSS:
CSS:
.search{
padding 0 10px;
font-size:0.8em;
float:right;
height:100%;
display:table;
vertical-align:middle;
}
.searchfield{
display:table-cell;
}
.searchbutton{
display:table-cell;
}
what am I doing wrong?
我究竟做错了什么?
回答by Jeff
Add a line-height equal to your font-size.
添加等于您的字体大小的行高。
.search{
padding 0 10px;
font-size:0.8em;
**line-height: 0.8em;**
float:right;
height:100%;
display:table;
vertical-align:middle;
}