stee1rat stee1rat -4 years ago 148
CSS Question

vertical-align:middle a div inside a floating div?

Why doesn't the black stripe in column three vertical-align in the middle of the parent div? Instead in aligns a little below the top. Is there a way to fix it?


<table border="1">
<td width='50' style='position:relative'>
<div class='data'>59853.94</div>
<div class="bar-chart-bar">
<div class="bar" style='width:50%; background-color:#B8E4F5'>
<div style="height:10px; background-color:black; width:100%;vertical-align:middle; display: inline-block"></div>
<td width="50">0</td>


.bar-chart-bar {
background-color: #e8e8e8;
display: block;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;

.bar {
float: left;
height: 100%;

.data {


.table > tbody > tr > td {
vertical-align: middle;

table {
font-size: 12px;

Answer Source

To your .bar class, you can add


as well as remove

vertical-align: middle;
display: inline-block;

from your .data class. Here is the result. The reason this wasn't working for you is that vertical-align doesn't really behave the way you want it to unless your element is in a table cell. See this for more about vertical align.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download