问题描述
|
我从未在任何网页上看到Computer Modern字体,这是LaTeX类型设置系统的默认字体。
如何更改CSS以使字体实际起作用?
解决方法
在网页中使用Computer Modern字体变得非常容易!只需将以下CSS代码行粘贴到html代码的头部即可激活该字体的sans-serif版本。
<style type=\"text/css\">
@font-face {
font-family: \"Computer Modern\";
src: url(\'http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf\');
}
@font-face {
font-family: \"Computer Modern\";
src: url(\'http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunsx.otf\');
font-weight: bold;
}
@font-face {
font-family: \"Computer Modern\";
src: url(\'http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunsi.otf\');
font-style: italic,oblique;
}
@font-face {
font-family: \"Computer Modern\";
src: url(\'http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunbxo.otf\');
font-weight: bold;
font-style: italic,oblique;
}
body {
font-family: \"Computer Modern\",sans-serif;
}
</style>
请注意,此处的解决方案使浏览器从CTAN镜像加载字体的当前版本,这可能会非常慢。可以进行测试,但从长远来看,我建议您将这些.otf文件下载到自己的Web服务器上。
, 现在,您可以从此网页下载所需的所有内容(字体文件和CSS):
http://checkmyworking.com/cm-web-fonts/
然后,您唯一需要做的就是将相应的CSS文件添加到html文件的标头部分,例如:
<head>
<meta charset=\"UTF-8\" />
<title>Test</title>
<!-- Computer Modern Serif-->
<link rel=\"stylesheet\" href=\"fonts/Serif/cmun-serif.css\"></link>
...
</head>
, 您可以将the2ѭcss-stylesheet插入html标头中。像这样:
<head>
<!-- ... -->
<link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.rawgit.com/dreampulse/computer-modern-web-font/master/fonts.css\">
<style>
body {
font-family: \"Computer Modern Sans\",sans-serif;
}
</style>
</head>
您可以将字体用于生产量很大的生产网站。文件通过MaxCDN的超快速全局CDN提供。没有流量限制或节流。
GitHub上的README.md
, 在CSS 2.1之前,您不能使用只能在客户端计算机上实际安装的字体。在CSS 3中,有一些将字体嵌入到网页中的方法,但是浏览器尚未大力支持这些方法。
在这里看看:http://home.tiscali.nl/developerscorner/fdc-varia/font-embedding.htm
, @font-face {
font-family: \"Computer Modern \";
src: url(ace.ttf);
}
。厘米 {
字体家族:\“ Computer Modern \”;
}
您确实需要使用该字体的ttf文件。