2013-11-27 121 views
2

我有這個div中心一個div的垂直內容

HTML:

<div draggable="false" id="coffe">Free coffee</div> 

CSS:

div { 
    position: absolute; 
    overflow: auto; 
    text-align: left; 
    font-size: 23px; 
    color: rgb(26, 66, 108); 
    font-family: roboto, Helvetica; 
    font-style: normal; 
    font-weight: bold; 
    -webkit-transition: none; 
    transition: none; 
    left: 0px; 
    top: 67.125px; 
    width: 1029.25px; 
    height: 234.93749999999997px; 
    opacity: 1; 
    background: grey; 
} 

,我需要垂直居中的內容,這是「免費咖啡」。

我該怎麼做?我嘗試了vertical-align: middle;但它不起作用。

這是小提琴文件:http://jsfiddle.net/2Mb39/

+0

的[中央單可能重複和多行垂直文本](http://stackoverflow.com/questions/4095165/center-single-and-multi-line-li-text-vertically) – isherwood

+0

或http://stackoverflow.com/questions/4952943/vertically-center -align-text – isherwood

+0

或http://stackoverflow.com/questions/12649287/vertically-centering-inline-content-using-line-height – isherwood

回答

8

指定匹配<div>的高度line-height

line-height: 235px; 

看到這個jsFiddle Demo

+0

嗨,它的作品就像一個魅力。謝謝BenM。 –

+0

沒問題。你可能想接受答案,如果它有幫助;) – BenM

+0

嗨,但我需要另一件事情,如果可能的話....我編輯我的帖子... –