Css 带有图像背景和文本的按钮

Css 带有图像背景和文本的按钮,css,button,Css,Button,我有一个应用了图像背景的按钮。按钮标签内有一些文字。要使文本居中,我使用填充来定位它。但是,每次我更改位置内的文本都会受到影响,我需要再次修复填充。有没有一种方法可以使文本无论长度都居中 我的代码: <button type="button" class="scroll_button" id="scroll">SIGN UP NOW</button> .scroll_button{ background: url('../images/button_arrow.png

我有一个应用了图像背景的按钮。按钮标签内有一些文字。要使文本居中,我使用填充来定位它。但是,每次我更改位置内的文本都会受到影响,我需要再次修复填充。有没有一种方法可以使文本无论长度都居中

我的代码:

 <button type="button" class="scroll_button" id="scroll">SIGN UP NOW</button>

.scroll_button{
background: url('../images/button_arrow.png') no-repeat 0 0;
padding: 24px 65px 45px 35px;
border: 0;
float: left;
margin-top: -100px;
color: white;
text-transform: uppercase;
font-size: 16px;
cursor: pointer;
}
立即注册
.滚动按钮{
背景:url('../images/button_arrow.png')不重复0;
填充:24px 65px 45px 35px;
边界:0;
浮动:左;
利润上限:-100px;
颜色:白色;
文本转换:大写;
字体大小:16px;
光标:指针;
}

移除
填充物
并替换为:

text-align:center;

拆下
衬垫
并替换为:

text-align:center;

您可以使用
文本对齐:居中
水平居中,并且
行高
设置为父容器的任何高度都可以垂直居中文本。

您可以使用
文本对齐:居中
水平居中,并且
行高
设置为父容器的任何高度都可以垂直居中文本。

您可以使用
文本对齐:居中
将文本水平居中放置在按钮内。将高度和宽度设置为所需的大小,然后使用
行高度:/*unit*/使其垂直居中(其中单位等于图元的高度)

.scroll_button{
background: url('../images/button_arrow.png') no-repeat 0 0;
border: 0;
float: left;
margin-top: -100px;
color: white;
text-transform: uppercase;
font-size: 16px;
cursor: pointer;

    /*centering. adjust to taste*/
    width: 150px;
    height: 50px;
    text-align: center;
}​

您可以使用
文本对齐:居中;
在按钮内水平居中文本。设置高度和宽度使其达到所需大小,然后使用
行高:/*单位*/;
垂直居中(单位等于元素高度)

.scroll_button{
background: url('../images/button_arrow.png') no-repeat 0 0;
border: 0;
float: left;
margin-top: -100px;
color: white;
text-transform: uppercase;
font-size: 16px;
cursor: pointer;

    /*centering. adjust to taste*/
    width: 150px;
    height: 50px;
    text-align: center;
}​

这样做-

padding: 24px 0px; width: 250px; text-align: center;

.scroll_button{
background: red;
padding: 24px 0px; width: 250px; text-align: center;
border: 0;
float: left;
color: white;
text-transform: uppercase;
font-size: 16px;
cursor: pointer;
}

这样做-

padding: 24px 0px; width: 250px; text-align: center;

.scroll_button{
background: red;
padding: 24px 0px; width: 250px; text-align: center;
border: 0;
float: left;
color: white;
text-transform: uppercase;
font-size: 16px;
cursor: pointer;
}

我指定了宽度和高度,添加了文本居中对齐和删除了填充,这样做有效谢谢:)我指定了宽度和高度,添加了文本居中对齐和删除了填充,这样做有效谢谢:)