2013-05-02 89 views
0

我的大脑被炸,所以我需要你们帮忙。简单的垂直对齐问题div

我想在div中做垂直对齐。

HTML

<a href='#'> 
    <div class="div"> 
    <div class="insideDiv">text here</div> 
    </div> 
</a> 

我的CSS

a { 
    color: #006699; 
    text-decoration: none; 
    font-size: 10pt; 
    border-width: 0; 
    position: relative 
} 

.div{ 
    position: absolute; 
    background-color: red; 
    top: -75px; 
    left: 50px; 
    width: 100px; 
    height: 50px; 
    z-index: 1000; 
    padding: 8px; 
} 

.insideDiv{ 
    background-color: white; 
    width: 100px; 
    height: 47px; 
    border: solid 1px grey; 
    font-weight: bold; 
    vertical-align: middle; 
    text-align: center; 
} 

好像text here不能垂直对齐到中年,但水平对齐中心。任何人都可以帮我解决这个问题吗?非常感谢!

+0

可能重复的[垂直对齐文本在Div](http://stackoverflow.com/questions/2939914/vertically-align-text-in-a-div) – lifetimes 2013-05-02 00:19:24

+0

我认为,有'div'在'a'中给你错误,正好在wh3c – jhunlio 2013-05-02 00:32:54

回答

2

vertical-align属性并不适用于块级元素,只在内嵌格式化的内容元素和表格细胞

您可以向.insideDiv类添加display: table-cell;垂直居中其文本:

例如:http://jsfiddle.net/Adrift/qTkAN/1/

+1

在我需要的时候。非常感谢! – Rouge 2013-05-02 00:40:00