Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically align text after div

I'm building an html bar graph using tables and nested divs and want to display the % as text immediately following the div bar.

I'm having a real problem centering this text vertically with the div - I've tried messing with vertical-align/line-height and various display options but to no avail. Can anyone point me in the right direction? I need a general solution - no absolute positioning.

The html:

<table>
  <tr>
    <td>
      Choice A
      <br>
      <div class="full">
        <div class="a"></div>
      </div>
      <span>50%</span>
    </td>
  </tr>
</table>

The css:

td {
  text-align: left;
}
.full {
  background-color: grey;
  width: 250px;
  height: 25px;
  display: inline-block;
  line-height: 25px;
}
.a {
  background-color: red;
  width: 50%;
  height: 100%;
}
span {
  vertical-align: middle;
}

http://jsfiddle.net/2n9aL/

like image 260
user3273906 Avatar asked Sep 25 '26 01:09

user3273906


1 Answers

do it different like

span {
    vertical-align: top;
}

Demo.

Or do

span {
    line-height: 25px;
    vertical-align: top;
}

Demo.

like image 59
user3395352 Avatar answered Sep 26 '26 16:09

user3395352



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!