2014-01-08 62 views
-2

在这里,你可以展示我的代码示例:Jsfiddle垂直文本中心

<div id="gameTimeBar-holder"> 
<div id="gameTimeBar"></div> 
<div class="progressBarText">Actions : 852 minutes</div> 

#gameTimeBar-holder{width:200px;height:15px;background:grey; position:absolute; top:45px; left:5px;} 
#gameTimeBar{width:0;height:100%;background:purple;} 
.progressBarText{position:absolute;z-index:10;top:0;left:0;width:100%;text-align:left; color: white;} 

我怎么能垂直中心我的文字在div progressBarText?

回答

2

添加line-height到文本
试试这个:

.progressBarText{ 
     position:absolute; 
     z-index:10; 
     top:0; 
     left:0; 
     width:100%; 
     line-height:15px; 
     text-align:left; 
     color: white; 
    } 

DEMO

+0

噢,是的,这很简单..谢谢! –

+0

很高兴帮助你:) @ClémentAndraud –

+0

这只是滥用'line-height'。如果他有多行文字会怎么样。 – crush