1

我正在尝试创建 html 屏幕。这些是模型屏幕,不会部署在任何应用程序服务器中。我创建了自定义字体,我需要通过 CSS 引用它们。

我的index.htmlfonts文件夹位于以下位置。

D:\index.html
D:\fonts

我在 CSS 文件中有以下代码:

@font-face{font-family:"MyRegular";
src:url('fonts/mycotext_rg.eot');
src:url('fonts/mycotext_rg.eot?#iefix') format('eot'),
    url('fonts/mycotext_rg.woff') format('woff'),
    url('fonts/mycotext_rg.ttf') format('truetype'),
    url('fonts/mycotext_rg.svg') format('svg');
font-weight:"normal"}

如果我应用字体系列,则不应用样式。我怎样才能参考cutom字体?我的网址引用正常还是需要更改?

谢谢!

4

3 回答 3

2

下面的两个答案都很好,并向您展示如何引用您的字体(通过使用font-family您的@font-face.local在引用其他源之前,系统上已经安装了字体。使用 Open Sans 示例,您可以使用:

src: local('Open Sans Bold'), local('OpenSans-Bold'), url(fonts/opensans-bold.woff) format('woff');

然后,只有在本地尚未找到该字体时,才会从您的 URL 下载该字体。

于 2013-06-24T09:04:55.560 回答
0

try this

When u apply @font face write down example,

body{
font-family:'MyRegular';
}

Add this in your CSS & also eot, svg, woff, ttf font file in your CSS folder :

@font-face{font-family:"MyRegular";
src:url('fonts/mycotext_rg.eot');
src:url('fonts/mycotext_rg.eot?#iefix') format('eot'),
    url('fonts/mycotext_rg.woff') format('woff'),
    url('fonts/mycotext_rg.ttf') format('truetype'),
    url('fonts/mycotext_rg.svg') format('svg');
font-weight:"normal"}

If @font-face in Chrome is not working, than apply the CSS below:

       @font-face{font-family:"MyRegular";
        src:url('fonts/mycotext_rg.eot');
        src:url('fonts/mycotext_rg.eot?#iefix') format('eot'),
            url('fonts/mycotext_rg.svg') format('svg'),
            url('fonts/mycotext_rg.woff') format('woff'),
            url('fonts/mycotext_rg.ttf') format('truetype'),
            font-weight:"normal"

}
于 2013-06-24T06:06:02.153 回答
0

只需输入 font-family 值。在这种情况下,“ MyRegular ”。

例子:

的HTML:

<span class="special-font">Text</span>

CSS:

.special-font { font: 1em "MyRegular", sans-serif; }

如果您不想使用类似的速记属性font,只需使用font-family

.special-font { font-family: "MyRegular", sans-serif; }

您可以添加多种字体,用逗号分隔它们。

这是一个带有Droid Sans字体的演示。

关于您是否正确引用了您的字体,如果您在外部 CSS 文件中,则您的相对路径是错误的!您必须在 Web 服务器目录中上一级。在你的情况下:

../fonts/Your_Font

您可以使用这种语法(是的!即使在 Windows 操作系统中)。这是一个很好的做法,因为如果您将网页/网站/Web 应用程序更改为具有不同文件系统(如 UNIX)的另一个操作系统,您的路径将起作用。

干杯,莱昂纳多

于 2013-06-24T06:04:10.923 回答