html - 我有一个带有文本的按钮,但文本未在按钮中居中。它不是在中间,而是在按钮的左上角

标签 html css button text

那么如何让文本位于按钮中间呢?

<style type="text/css">
a {
text-decoration: none;
font-size: 14px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: bold;
background-color: #CC4A31;
color: #444;
border-radius: 9px;
position: absolute;
top: 16px;
left: 40px;
height: 50px;
width: 125px;
webkit-box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.125);
box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.125);
</style>


<a href="">GameTrade</a>

最佳答案

您可以添加以下内容:

text-align: center;
line-height: 50px;

在你的类(class)。

如果添加相同的高度和行高,文本将始终居中。

这是 CSS 中的:

height: 'x' px;
line-height: 'x' px;

您可以在这里看到不同尺寸的。观察文本如何始终居中,尽管大小不同。

http://jsfiddle.net/ywdHq/1/

关于html - 我有一个带有文本的按钮,但文本未在按钮中居中。它不是在中间,而是在按钮的左上角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24045211/

相关文章:

html - 在 Bootstrap 中以一定的精度将图像彼此重叠放置

html - 页面加载并向上推布局

javascript - jQuery - Google 图像功能在点击时滚动到无序列表行的顶部

c - 使用 C 在 win32 中运行时 move 按钮的 x 位置

javascript - 使用 Bootstrap 固定高度列

javascript - fullPage.js 一页滚动 - 在最后一节之后无法滚动到页脚

css - 如何在边界框中保持图像的纵横比 - CSS

javascript - Datatables JS - 基于数据值排名的条件格式

html - 输入按钮目标 ="_blank"不会导致链接在新窗口/选项卡中加载

python - 销毁按钮的旧回调并安装新回调