css - 如何垂直居中对齐按钮内的文本?

标签 css button

我认为line-height会垂直居中对齐文本。但我的按钮却没有发生这种情况。为什么?

文本在 FF、Opera 和 Safari 中底部对齐。

Her is my fiddle .

<button class="get_discount_rate">Button</button>
button {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: normal;
  color: #444;
  min-width: 90px;
  height: 24px;
  line-height: 24px;
  margin: 5px 10px;
  background-color: #fdfdfd;
  border: 1px solid #cdcdcd;
  cursor: pointer;
  border-radius: 3px;
}

最佳答案

按钮内的文本垂直居中对齐(在 Chrome、FF、Safari、Opera 和 IE8 中测试)

button {
    font-family: Arial, Helvetica, sans-serif;
    font-weight: normal;
    color: #444;
    min-width: 90px;
    padding:5px;
    margin: 5px 10px;
    background-color: #fdfdfd;
    border: 1px solid #cdcdcd;
    cursor: pointer;
    border-radius: 3px;
}​

DEMO.

关于css - 如何垂直居中对齐按钮内的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11596341/

相关文章:

html - 如何以响应方式定位 6 个 Bootstrap 容器?

html - 使用 CSS 创建 Masonry 布局?

html - css 复选框在 :checked state 时不应用更改

html - 用外部 CSS 覆盖 Bootstrap 主按钮

ios - 如何修复自定义按钮在 SwiftUI(IOS) 中的交互?

javascript - 有没有一种添加新框并使用 javascript 重绘 Canvas 的好方法?

html - CSS 在逗号上打断单词

android - Android中如何读取当前按钮的背景图?

c# - 以编程方式更改 WPF 中的按钮图标

c# - C# WinForms 中的切换按钮