css - 在 div 中垂直居中文本

标签 css positioning centering

我在将下面的 div 中的文本垂直居中时遇到了很多麻烦。如果有人可以帮助我完成这项工作,我将不胜感激。

这是我尝试过的:

<div class="input-label" style="vertical-align:middle;">Toys:</div>

这是我当前的标记:

<div class="input-label" >Toys:</div>

CSS

.input-label
{
   background-color:#7a86d0; 
   height:30px; 
   float:left; 
   width:130px; 
   text-align:right; 
   font-weight:bold; 
   padding-right:10px; 
}

非常感谢!

最佳答案

尝试将 line-height: 30px; 添加到您的 CSS。

关于css - 在 div 中垂直居中文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14758195/

相关文章:

javascript - 滑动框错误

css在一个div中定位2个div

css - 无法在页面上水平居中元素

html - polymer 纸工具栏忽略正文边距

jquery - Team Treehouse 导航栏动画

css - 在单行上获取文本和选择框

html - 通过 CSS 响应式设置 div 的高度

html - 智能页面调整大小

jquery - 中心 SVG 图表宽度 jQuery

css - 垂直居中段落