2017-01-14 58 views
0

出於某種原因,我的文本不在我按鈕的垂直中心。將文本置於按鈕的中央

button { 
 
    height: 35px; 
 
    padding: 20px;
<button> 
 
Hi 
 
</button>

我需要保持填充和高度,因爲它是

+1

只需刪除高度。 –

+0

我需要保持它那個高度 – JugglingBob

回答

0

試試這個增加高度和寬度按規定

button { 
 
    height: 50px; 
 
    width:60 
 
<button> 
 
Hi 
 
</button>

0

button { 
 
    height: 35px; 
 
    padding: 0 20px; 
 
}
<button> 
 
Hi 
 
</button>

+0

我想保持填充我有 – JugglingBob

+0

那麼你需要不定義高度 – Banzay

+0

我需要定義的高度和填充。有沒有其他的東西我可以使用 – JugglingBob

1

然後取出頂部和底部填充

button { 
 
    height: 35px; 
 
    padding:0 20px; 
 
} 
 
<button> 
 
Hi 
 
</button>

+0

謝謝!!!!!!!! – JugglingBob

+0

@JugglingBob歡迎:) –

0

button { 
 
    height: 35px; 
 
    padding: 20px; 
 
    line-height: 0px; 
 
    }
<button> 
 
Hi 
 
</button>
添加0像素的行高。

請參閱的jsfiddle: -

https://jsfiddle.net/

0

這是因爲您已設置的高度35px並填充到20像素周圍的所有按鈕。這實際上會使按鈕的高度爲40px。

所以解決方法是刪除頂部和底部填充,並將高度設置爲40px。

button { 
 
    height: 40px; 
 
    padding: 0 20px; 
 
}
<button> 
 
Hi 
 
</button>

另一種解決方案也可以是設置line-height爲0,但上述的解決辦法是更有意義,因爲按鈕其實是在高度爲40個像素,而不是30。