在 CSS 中使用自定义 (ttf) 字体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7512468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using a custom (ttf) font in CSS
提问by JJJollyjim
I have a mac, and have installed a font called "7 Segment" (it shows up in Font Book). When I use font-family: "7 Segment";
I get Helvetica (or similar) rather than the browser's default font, but it still isn't showing the correct font. The page only needs to be shown on this computer. How would I use the font on this page? Thanks.
我有一台 mac,并安装了一种名为“7 Segment”的字体(它显示在 Font Book 中)。当我使用时,font-family: "7 Segment";
我得到 Helvetica(或类似字体)而不是浏览器的默认字体,但它仍然没有显示正确的字体。该页面只需要在这台计算机上显示。我将如何使用此页面上的字体?谢谢。
回答by JNDPNT
You need to use the css-property font-face to declare your font. Have a look at this fancy site: http://www.font-face.com/
您需要使用 css-property font-face 来声明您的字体。看看这个花哨的网站:http: //www.font-face.com/
Example:
例子:
@font-face {
font-family: MyHelvetica;
src: local("Helvetica Neue Bold"),
local("HelveticaNeue-Bold"),
url(MgOpenModernaBold.ttf);
font-weight: bold;
}
See also: MDN @font-face