2011-02-01 56 views
0
.st_content_heading{ 
width:500px; 
height:250px; 
background:red; 
border:1px solid #ccc; 
float:left; 
margin:0px; 
padding:0px; 
display:table-cell; 
vertical-align:middle; 
} 
<div class="st_content_heading" style="vertical-align:middle;">Content for class "st_content_out" Goes Here</div> 

回答

6

如果浮動元素,則會丟失表格單元狀態。

.st_content_heading{ 
width:500px; 
height:250px; 
background:red; 
border:1px solid #ccc; 
/* float:left; take this out */ 
margin:0px; 
padding:0px; 
display:table-cell; 
vertical-align:middle; 
} 
+0

感謝它的工作..如果我當時需要使用「float:left」,我該怎麼辦? – sridhar 2011-02-01 14:24:17

0

此解決方案完美匹配我。即使它是一個鏈接或div內的文本,這個CSS類可以垂直對齊DIV內的內容

.verticalCenterDivText{ 
    height: 29px; 
    line-height: 29px; 
} 

希望這會有所幫助。