5

I suspect that this can't be done, but I'm asking just to be sure.

I'd like to force a single character in a <span> to have a specific width and height: 1em.

Ideally the character would be stretched to 1em if it is not already fixed-width.

This must support any character, including rare Unicode glyphs, so I cannot just set the font to Courier.

Finally, this should be accomplished with only CSS, and be simple and lightweight. E.g. a complex solution which includes a div within a table containing a one-pixel image (just to display this single character) is not OK.

I can't remember any property which does this, and attempts to Google have just returned a lot of "fixed width layouts" and nothing about single characters.

If there is no simple solution, but there is a complex one, I won't use it, but I'd be curious to hear it anyway.

Pops
  • 30,199
  • 37
  • 136
  • 151
o0'.
  • 11,739
  • 19
  • 60
  • 87
  • 1
    This question is similar to another stack overflow question: http://stackoverflow.com/questions/4258872/limiting-characters-to-a-specfic-width – Brian Clapper Mar 10 '11 at 15:15
  • 1
    @Brian, that question doesn't specify a formatting strategy -- though it is tagged `[php]` -- while this one explicitly requests CSS. – Pops Mar 10 '11 at 15:16
  • 2
    That's why I didn't vote to close this question as a duplicate. It's a related issue, but not exactly the same. – Brian Clapper Mar 10 '11 at 15:17
  • @Brian, okay, fair enough. I wouldn't even call them similar enough for the comment, but that's getting really subjective and non-productive. – Pops Mar 10 '11 at 15:20

2 Answers2

5

You can use @font-face to include a fixed width font with good unicode support. The DejaVu family has excellent unicode support and a mono variant, and should do this nicely. You can use FontSquirrel's @font-face generator to create the files you need for this.

Yi Jiang
  • 49,435
  • 16
  • 136
  • 136
3

While I like Yi Jiang's answer, I think you might be better served by GNU Unifont based on the short discussion at this page and Wikipedia's list of typefaces with good Unicode support. Notably, that first page points out that DejaVu Sans Mono misses some glyphs which, depending on your application, may be fairly common.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Pops
  • 30,199
  • 37
  • 136
  • 151
  • DejaVu Sans Mono currently offers most (maybe all) of the characters that were mentioned as missing in the article you linked to. – Marconius Mar 22 '12 at 02:02
  • Hm, it's blocked here at work now, but I'll try to check this out later, thanks for the tip. – Pops Mar 22 '12 at 14:04