文本对齐垂直在div中不起作用?

sri*_*har 0 css

.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>
Run Code Online (Sandbox Code Playgroud)

met*_*ion 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;
}
Run Code Online (Sandbox Code Playgroud)

  • 如果答案是正确的,最佳做法是点击我的答案旁边的复选标记.这允许其他用户找出哪个答案是正确的. (4认同)