I made this response based on your HTML, but it is not correct to use a block element (the div
in the case), within table
, because they have different scopes, a display:table
com children table-cell
, the other is display:block
.
Given this I made a suggestion within what I understood is your problem ... I have used display:flex
in div
who now play the role of TD
and container
playing the% with%. With table
I can align items in column form ( flex
) and use the column
and justify-content: center;
properties to center horizontally and vertically.
With regard to label of the graph column you can create a pseudo-element for each column, and use align-items: center;
type custom atributo
in data-texto
type like this: content
and in the div like this: content: attr(data-texto);
Then you put a <div data-texto="texto" ...>
and top: 0;
to place the text on the bar regardless of its size
See the example to better understand how it looks. I tried to tweak as little as possible in your HTML
.container {
display: flex;
justify-content: center;
text-align: center;
height: 130px;
background-color: #ddd;
}
.container .barra {
display: flex;
flex-direction: column;
height: 100%;
padding: 5px 0 5px;
box-sizing: border-box;
justify-content: flex-end;
}
.container .barra1 {
width: 80px;
background-color: #f00;
margin: 0 10px;
height: 50px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: relative;
}
.container .barra1::after {
content: attr(data-texto);
position: absolute;
top: 0;
transform: translateY(-100%);
text-align: center;
}
<div class="container">
<div class="barra">
<div data-texto="texto 123 456" class='barra1' style="height:50px" data-toggle="tooltip" data-placement="right">Valor: 5,0 <br> 29%</div>
</div>
<div class="barra">
<div data-texto="texto" class='barra1' style="height:75px; background-color: #ff0;" data-toggle="tooltip" data-placement="right">Valor: 5,0 <br> 60%</div>
</div>
<div class="barra">
<div data-texto="paralelepípedo" class='barra1' style="height:100px; background-color: #0f0;" data-toggle="tooltip" data-placement="right">Valor: 5,0 <br> 90%</div>
</div>
</div>