Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set width of <div> to fit constant number of letters in monospace font?

I researched for a while, hasn't found a CSS solution yet, em and ex units are not correct in this case. What I want is simply a div box that exactly fits 80x25 monospace text. Do I have to resort to Javascript solutions?

like image 625
btw0 Avatar asked Aug 10 '09 14:08

btw0


1 Answers

Try using the ch unit described in the CSS3 specification:

Equal to the used advance measure of the "0" (ZERO, U+0030) glyph found in the font used to render it.

Thus width: 80ch specifies an 80 character width limit.

like image 117
sunaku Avatar answered Sep 21 '22 05:09

sunaku