2014-09-23 67 views
0

我正在玩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> 

回答

3

如果它只有一行文字,比我平時使用line-height = height

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

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

+0

非常感謝。這工作完美。 – RGriffiths 2014-09-23 11:05:10

1

使用「Vertical-align:middle;」在你a.button css規則。

+0

這似乎沒有工作。 – RGriffiths 2014-09-23 11:05:29