如何使用CSS获取具有等宽文本的HTML文本区域?

问题描述:

这可能是一个愚蠢的noob问题,但我不知道如何使我的文本区域使用等宽字体。

This may be a dumb noob question, but I can't figure out how to make my text area use a monospaced font.

如果我的理解正确,它应该已经继承默认的用户代理样式,但是如果你想显式地,只需指定一个字体族(从Stackoverflow样式表填充的样式)

If I'm understanding properly, it should already inherit default user-agent styles, but if you want to explicitly, just specify a font-family ( styles jacked from Stackoverflow stylesheet )

textarea {
  font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New, monospace;
}

首先指定更具体用户代理没有可用,它将持续尝试它们直到结束,在这种情况下,它将默认为该元素的默认用户代理字体系列(如果指定任何)。

Specify the more specific (monospace-specific) font families first, and if the user agent doesn't have that available it will keep trying them until the end, in which case it would default to the default user agent font family for that element, if any was specified.