简体   繁体   English

将CSS3按钮上的文本居中错误

[英]Error centering text on CSS3 button

I am trying to center the text "verksamheter" on my CSS3 button, but I can't get it to work. 我试图将文本“verksamheter”置于我的CSS3按钮中心,但我无法让它工作。

HTML: HTML:

<a href="#" class="verksamheter"><span>Verksamheter</span></a>

CSS: CSS:

.verksamheter {
  width: 220px;
  height: 44px;
  font-style: italic;
  font-size: 18px;
  display: inline-block;
  text-align: center;   
  -webkit-border-radius: 22px;
  -moz-border-radius: 22px;
  border-radius: 22px;
  background-color: #ebebeb;
  -webkit-box-shadow: 0 1px rgba(0,0,0,.13), inset 0 2px rgba(255,255,255,.75);
  -moz-box-shadow: 0 1px rgba(0,0,0,.13), inset 0 2px rgba(255,255,255,.75);
  box-shadow: 0 1px rgba(0,0,0,.13), inset 0 2px rgba(255,255,255,.75);
  border: solid 1px #4f4d6a;
  background-image: -webkit-linear-gradient(top, #6e6c8a, #4f4d6a);
  background-image: -moz-linear-gradient(top, #6e6c8a, #4f4d6a);
  background-image: -o-linear-gradient(top, #6e6c8a, #4f4d6a);
  background-image: -ms-linear-gradient(top, #6e6c8a, #4f4d6a);
  background-image: linear-gradient(to bottom, #6e6c8a, #4f4d6a);   
}

.verksamheter span {
  vertical-align: middle;
}

The height of the <a> is 44px, so make the line-height of the text 44px as well. <a>的高度为44px,因此也可以使文本44pxline-height

http://jsfiddle.net/s4KJd/ http://jsfiddle.net/s4KJd/

Simply set the line-height property according to the height of the element and the font size used. 只需根据元素的高度和使用的字体大小设置line-height属性。 For example: 例如:

.verksamheter {
    line-height: 44px;
}

Here's a jsFiddle Demo . 这是一个jsFiddle演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM