问题描述
我有一些(测试)HTML:
I have some (test) HTML like so:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test Monospace</title>
<style>
tt { font-family: monospace; }
</style>
</head>
<body>
<h1>Test Monospace</h1>
<p>This is normal text</p>
<p><tt>This is monospaced text</tt></p>
</body>
</html>
当我在IE中显示这个等宽字体文本使用Courier New而不是我在IE中配置的字体。如果我除了删除< style> ...< / style>
块,除了正确使用配置的字体之外什么都不做。
When I display this in IE the monospace text uses Courier New instead of the font I have configured in IE. If I do nothing other than delete the <style>...</style>
block, it correctly uses the configured font.
它只对IE,而不是FF或GC。 IE 9在Windows 7上。
It only does this for IE, not FF or GC. IE 9 on Windows 7.
无论样式配置在哪里,都会这样做,包括单独的样式表或样式属性。
It does this regardless of where the style's configured, including a separate stylesheet or using a style attribute.
真正的问题是,指定font-family和font-size是使用以下样式修复浏览器的问题的关键:
The real problem is that specifying the font-family and font-size is key to fixing the browser's problems with monospace text using the following styles:
/* monospaced sizes are horribly broken in browser default stylesheets */
code, kbd, pre, samp, tt {
font-family : monospace,monospace; /* Chrome (but note that this makes IE use "Courier New" for some strange reason, as does plain monospace.) */
font-size : 1em; /* Firefox, IE,Opera */
}
有人知道如何停止IE从这样做?
Does anyone know how to stop IE from doing this?
推荐答案
monospace
不是一个特定的字体familiy。完全像 serif
或 sans-serif
,是通用家族定义。
monospace
is not a specific font familiy. Exactly like serif
or sans-serif
, which are generic family definitions.
font-family:monospace;
只是告诉浏览器使用默认的,在这种情况下是Courier New。另请参见。
font-family: monospace;
just tells the browser to use the default "monospaced font", which in this case is Courier New. See also this resource.
编辑:
如果省略 font-family
code> tt 在你的CSS中,IE9似乎显示自定义的纯文本字体。请看这个小提琴:
If you omit the font-family
rule for tt
in your CSS, IE9 seems to display the custom set plain text font. Please see this fiddle: http://jsfiddle.net/sVCwd/1/
希望这有帮助。
这篇关于IE使用Courier字体,当“font-family:monospace”用来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!