将文本居中于按钮CSS

时间:2014-09-23 10:46:33

标签: html css

我正在使用CSS和按钮,我希望文本历史记录位于按钮的中心,但它出现在单元格的顶部。我怎样才能将它垂直插入中间?

enter image description here

CSS

a.button {
background: url(button.png) no-repeat 0 0;
width: 150px;
height: 62px;
display: block;
}

HTML

<td  align="center" valign="middle" >
<a href="history.htm" class="button"/><b>HISTORY</b></a>
</td>

2 个答案:

答案 0 :(得分:3)

如果它只有一行文字,那么我通常会使用line-height = height

&#13;
&#13;
a.button {
  background: green;
  width: 150px;
  height: 62px;
  display: block;

  line-height: 62px;
  text-align: center;
}
&#13;
<a href="history.htm" class="button"/><b>HISTORY</b></a>
&#13;
&#13;
&#13;  

答案 1 :(得分:1)

使用&#34;垂直对齐:中间;&#34;在你的a.button css规则。