@font-face 未嵌入移动 Safari (iPhone/iPad)

发布于 2024-10-06 18:05:56 字数 993 浏览 0 评论 0原文

我使用 @font-face (来自 FontSquirrel 的 CSS)在移动网站上嵌入字体。当我在桌面 Safari 或 Chrome 中预览时,字体嵌入得很好,但它们不会出现在 iPhone/iPad 上的移动 Safari 中。我没有收到任何错误,我也不知道出了什么问题。这是我的 CSS。有什么想法吗?

@font-face {
    font-family: 'JottingRegular';
    src: url('../fonts/jotting_regular-webfont.eot');
    src: local('☺'),
         url('../fonts/jotting_regular-webfont.woff') format('woff'),
         url('../fonts/jotting_regular-webfont.ttf') format('truetype'),
         url('../fonts/jotting_regular-webfont.svg#webfonttEfFltbI') format('svg');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'JottingBold';
    src: url('../fonts/jotting_bold-webfont.eot');
    src: local('☺'),
         url('../fonts/jotting_bold-webfont.woff') format('woff'), 
         url('../fonts/jotting_bold-webfont.ttf') format('truetype'), 
         url('../fonts/jotting_bold-webfont.svg#webfontJpUFTHYS') format('svg');
    font-weight: normal;
    font-style: normal;
}

I'm embedding fonts on a mobile website using @font-face (css from FontSquirrel). When I preview in desktop Safari or Chrome, the fonts embed fine, but they don't appear in mobile Safari on the iPhone/iPad. I'm not getting any errors and I can't figure out what's going wrong. Here's my CSS. Any ideas?

@font-face {
    font-family: 'JottingRegular';
    src: url('../fonts/jotting_regular-webfont.eot');
    src: local('☺'),
         url('../fonts/jotting_regular-webfont.woff') format('woff'),
         url('../fonts/jotting_regular-webfont.ttf') format('truetype'),
         url('../fonts/jotting_regular-webfont.svg#webfonttEfFltbI') format('svg');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'JottingBold';
    src: url('../fonts/jotting_bold-webfont.eot');
    src: local('☺'),
         url('../fonts/jotting_bold-webfont.woff') format('woff'), 
         url('../fonts/jotting_bold-webfont.ttf') format('truetype'), 
         url('../fonts/jotting_bold-webfont.svg#webfontJpUFTHYS') format('svg');
    font-weight: normal;
    font-style: normal;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

救星 2024-10-13 18:05:56

好的,我已经弄清楚了,并将为将来遇到此问题的任何人记录下来。我从 Font Squirrel 复制了 CSS,然后我需要稍后重新下载实际的字体文件。我认为这不会改变 CSS 中的任何内容,但事实证明,SVG 字体(由 mobile safari 使用)都有一个在字体文件和 CSS 中引用的 ID。

所以,在:

url('../fonts/jotting_regular-webfont.svg#webfonttEfFltbI') format('svg')

webfonttEfFltbI中就是字体id。我在文本编辑器中打开 SVG 字体文件,并在文件顶部附近的以下行中找到了新 ID:

<font id="webfontC6xdxB57" horiz-adv-x="972" >

在 CSS 中的哈希标记后替换 id 修复了问题。

OK, I figured it out and will document for anyone who has this problem in the future. I had copied the CSS from Font Squirrel and then I had needed to redownload the actual font files later on. I didn't think that would change anything in the CSS, but it turns out that SVG fonts (which are used by mobile safari) all have an ID that is referenced in the font file and the CSS.

So, in:

url('../fonts/jotting_regular-webfont.svg#webfonttEfFltbI') format('svg')

webfonttEfFltbI is the font id. I opened the SVG font file in a text editor and found the new ID in the following line near the top of the file:

<font id="webfontC6xdxB57" horiz-adv-x="972" >

Replacing the id after the hash tag in the CSS fixed the problem.

无畏 2024-10-13 18:05:56

我也有同样的情况。我通过更新字体的路径解决了这个问题。尽管 Chrome 和Safari 加载它们很好,iOS 无法识别我的路径,

url ('font/chunkfive/font.eot')

我更改了该行以在字体路径的开头包含一个 / ,这解决了所有问题。

url ('/font/chunkfive/font.eot')

您也可以尝试使用绝对路径。

I was having this same situation. I resolved it by updating the paths to the font. Even though Chrome & Safari were loading them fine, iOS wasn't recognizing my path which was

url ('font/chunkfive/font.eot')

I changed that line to include a / to the beginning of the font path and that fixed everything.

url ('/font/chunkfive/font.eot')

You could also try using an absolute path.

灵芸 2024-10-13 18:05:56

在 iOS 4.2 之前,MobileSafari 不支持字体。

Font face isn't supported on MobileSafari until iOS 4.2.

三生一梦 2024-10-13 18:05:56

在意识到我的愚蠢错误之前,我已经为此工作了一个小时。

Mobile Safari 的字体区分大小写,而 Desktop Safari 则不区分大小写。

如果您的字体标题为:font.svg,则必须按照原样添加它。如果你用大写 F 添加它,桌面版 Safari 不会在意,但移动版会。

I had been working with this for a hour before realizing my stupid mistake.

Mobile Safari is CASE SENSITIVE for the fonts, while Desktop Safari is not.

If your font is titled: font.svg, you must add it exactly like it is. If you add it with a Capital F, Desktop Safari won't care, but mobile will.

念﹏祤嫣 2024-10-13 18:05:56

这已经解决了,但我在这里遇到了类似的问题:

@font-face 无法在移动 Webkit 中工作

对我来说,所有SVG 字体上的 ID 正确;奇怪的是 FontSquirrel 语法。使用更新的 FontSpring 防弹语法为我解决了这个问题,并且似乎完全可以跨浏览器工作。

This has already been solved, but I had a similar problem here:

@font-face not working in mobile Webkit

For me, all the IDs on the SVG fonts were correct; it was the FontSquirrel syntax that was wonky. Using the updated FontSpring bulletproof syntax fixed the issue for me, and seems to work entirely cross-browser.

美男兮 2024-10-13 18:05:56

Font Face 确实可以在 mobile safari 上使用,我在 iphone 3 上使用。我还复制了 font squirl 的代码,但它不起作用。这是更新后的代码。使用它,它将在任何地方都有效。

@font-face {
    font-family: 'MyriadProBoldCondensed';
    src: url('/fonts/myriadpro-boldcond-webfont.eot#') format('eot'),
         url('/fonts/myriadpro-boldcond-webfont.woff') format('woff'),
         url('/fonts/myriadpro-boldcond-webfont.ttf') format('truetype'),
         url('/fonts/myriadpro-boldcond-webfont.svg#MyriadProBoldCondensed') format('svg');
    font-weight: normal;
    font-style: normal;
}

Font face does work on mobile safari, i am using on iphone 3. I also copied the code from font squirl but it didn't work. Here is the updated code. Use this and it will work everywhere.

@font-face {
    font-family: 'MyriadProBoldCondensed';
    src: url('/fonts/myriadpro-boldcond-webfont.eot#') format('eot'),
         url('/fonts/myriadpro-boldcond-webfont.woff') format('woff'),
         url('/fonts/myriadpro-boldcond-webfont.ttf') format('truetype'),
         url('/fonts/myriadpro-boldcond-webfont.svg#MyriadProBoldCondensed') format('svg');
    font-weight: normal;
    font-style: normal;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文