Set CSS width to given number of characters
I have a block of text in a
<pre> element rendered with
font-family: monospace. I want to set the width of the
element to be 86 characters wide, the length of the longest line in
width: 86em doesn’t work here because it takes the current element’s
font-size, multiplies by 86, and sets that as the width. This would
work if, for a
font-size: 13px, each character was exactly 13px wide
but in my experience that won’t be the case.
What works, instead, is
width: 86ch which is the width of the “0”
(zero) character. But because we’re using a monospace font, “0” will
be the same width as all the other characters.