css - Progress bar as background of table -
i have html table showing list of person. each row, have different progressbar-like background.
<table> <tr class="progress-full">...</tr> <tr class="progress-half">...</tr> <tr class="progress-quarter">...</tr> </table>
with whole background of first row in color, half of secord , 1/4 of last 1 (with classes or using directly percentage in css).
i tried using background width (like here) didn't succeed. can enclose div inside tr ? when inspect html code (eg: chrome) div seems outside of table.
<table style="width: 300px;"> <tr style="width: 75%; background: rgb(128, 177, 133);"> <div style="width: 300px;">...</div> </tr> <tr style="width: 50%; background: rgb(128, 177, 133);"> <div style="width: 300px;">...</div> </tr> </table>
or maybe method ?
you avoid adding markup table if use css ::before
or ::after
pseudo-elements. can give each table row transparent background, , give pseudo-element width want.
here's jsfiddle example.
html:
<table> <tr class="progress-full"> <td>row 1 col 1</td> </tr> <tr class="progress-quarter"> <td>row 2 col 1</td> </tr> <tr class="progress-half"> <td>row 3 col 1</td> </tr> </table>
css:
td { padding: 10px; } tr.progress-full td:first-child, tr.progress-half td:first-child, tr.progress-quarter td:first-child { position: relative; } tr.progress-full td:first-child::before, tr.progress-half td:first-child::before, tr.progress-quarter td:first-child::before { content: ""; position: absolute; top: 0; left: 0; width: 0; height: 100%; background-color: red; z-index: -1; } tr.progress-full td:first-child::before { width: 100%; } tr.progress-half td:first-child::before { width: 50%; } tr.progress-quarter td:first-child::before { width: 25%; }
this css slimmed down, depending on how variable table structure is. applied styles onto first td
inside each tr
. if need progress bar stretch across multiple td
s, use width of greater 100%.
Comments
Post a Comment