2013-03-29 26 views
3

我想在CSS3按鈕上居中顯示「verksamheter」文本,但我無法使其正常工作。在CSS3按鈕上居中顯示文本錯誤

HTML:

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

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; 
} 

回答

2

只需根據元件的高度和所使用的字體大小設置line-height屬性。例如:

.verksamheter { 
    line-height: 44px; 
} 

這是jsFiddle Demo