CSS如何正确地用按钮背景替换链接
我正在尝试用按钮背景替换应用程序上的链接。但是,链接文本不会水平或垂直居中。我正在使用属性“背景位置:中心中心;”我认为这会解决我的问题。
我的 HTML:
<a class="violetButtonLarge" href="#">My Link</a>
CSS:
.violetButtonLarge {
display: block;
width: 304px;
height: 41px;
background: url(../images/violetButton_large.png) no-repeat center center;
border:none;
color: #FFFFFF;
font-weight: bold;
font-family: Arial;
background-color: transparent;
text-decoration: none;
}
我的图像:
我在这里做错了什么?这就是我得到的:
提前致谢!
I'm trying to replace the links on my app with a button background. However the link text won't center horizontally neither vertically. I'm using the property "background-position: center center;" which I assume would solve my problem.
My HTML:
<a class="violetButtonLarge" href="#">My Link</a>
CSS:
.violetButtonLarge {
display: block;
width: 304px;
height: 41px;
background: url(../images/violetButton_large.png) no-repeat center center;
border:none;
color: #FFFFFF;
font-weight: bold;
font-family: Arial;
background-color: transparent;
text-decoration: none;
}
My image:
What I'm I doing wrong here? This is what I get:
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
text-align:center
和line-height:41px
将文本垂直和水平居中对齐。示例:http://tinkerbin.com/q5VZR1At
Use
text-align:center
andline-height:41px
to align the text in the vertical and horizontal center.Example: http://tinkerbin.com/q5VZR1At
可能你应该设置填充,然后你不需要设置宽度和高度。
vertical-align:baseline
有助于将它们设置在与“真实”输入按钮相同的行上。编辑:抱歉,我没有在您的代码中看到该图像,也许您应该看一下这个很棒的示例: CSS 渐变按钮。
Probably you should set the padding, then you don't need to set the width and height. The
vertical-align: baseline
helps to set them on the same line with "real" input buttons.Edit: Sorry i didn't saw the image in your code, maybe you should get a glimpse at this great example: CSS Gradient Buttons.