I have a simple table with SVG in its table cell:
<html>
<body>
<table style="width: 8em;">
<tr>
<td style="border: 1px solid black;">
<svg viewBox="0 0 1 1" style="width: 1.37em;" preserveAspectRatio="none">
<polyline points="0,0 1,0.5 0,1" style="fill: blue;"></polyline>
</svg>
</td>
<td style="border: 1px solid black;">Lorem ipsum dolor sit amet</td>
</tr>
</table>
</body>
</html>
As you can see, other cells in the row can be too long, and hence cause the row height to change from the default, introducing gaps between the SVG and its bounding upper and lower borders.
How can I get the SVG to automatically stretch or shrink to fill its cell vertically, without changing its horizontal size?
2
Answers
I tried beatiful solutions but they didn’t work, If you are open to hacky stuff…
Position relative to the td so that the svg is contained inside it, because the svg is now position absolute so that it accepts height 100%, but position abosulte makes the element don’t ocupy space that why it’s needed to add width to the td
One solution would be to make it a background image. You can either put the SVG code into a separate file, or you can percent-encode it to use in a data URI.