view raw
stee1rat stee1rat - 6 months ago 41
CSS Question

position: absolute and vertical-align: middle

How to set the third column in my example to have

vertical-align: middle
as all the other rows? I realize that the problem is with
position: absolute
, but I can't figure out how to solve the issue.

Even positioning with top does not work for


<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>
<td width="50">0</td>


.bar-chart-bar {
background-color: #e8e8e8;
display: block;
position: relative;
width: 100%;
height: 20px;

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

.data {
position: absolute;
z-index: 1;
display: block;
top: 10;

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

table {
font-size: 12px;


Yes, you need to remove position: absolute from .data, and absolute position the .bar-chart-bar and set the z-index accordingly :

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