Is there a way to use the width of the glyphs from a mono-spaced font to set the font size using CSS?
For example, I want the 10 characters inside this box to each be exactly 20px wide such that the text exactly fills the box, regardless of which monospace font is actually used. Currently the font-size directive that I'm using sets the height of the font, not the width of each letter.
#xyzzy {
width: 200px;
padding: 0;
margin: 10px;
border: 10px solid black;
font-family: monospace;
font-size: 20px;
}
<div id=xyzzy>1234567890</div>
The reason that I'm looking for this is that I have some content to show on mobile in a monospace font that can't wrap or extend off the screen. I'd like to be able to show exactly 44 characters of text across a 320px screen. I can't seem to get the font sized correctly such that it looks good in all browsers. It either extends past the viewport or leaves white space to the right.