使用CSS font-family选择不适用于Android的Droid字体

sor*_*rin 6 fonts android font-face font-family

我发现以下HTML代码在Android上不起作用(它只使用默认字体:Droid Sans.在桌面上它正如预期的那样工作.

<p style='font-family: "Droid Sans",sans-serif;'>vând whisky ?i tequila, pre? fix.</p>
<p style='font-family: "Droid Sans Mono",monospace;'>vând whisky ?i tequila, pre? fix.</p>
<p style='font-family: "Droid Serif",serif;'>vând whisky ?i tequila, pre? fix.</p>
Run Code Online (Sandbox Code Playgroud)

tad*_*obi 1

您的 css 中可能没有其他字体的 @font-face 声明。我猜你只有一张 Droid Sans 的。每种字体都需要一个。例如,在你的 css 中你应该有:

\n\n
@font-face {\n    font-family: \'DroidSans\';\n    src: url(\'font/DroidSans-webfont.eot?\') format(\'eot\'),\n         url(\'font/DroidSans-webfont.woff\') format(\'woff\'),\n         url(\'font/DroidSans-webfont.ttf\') format(\'truetype\'),\n         url(\'font/DroidSans-webfont.svg#webfontw7zqO19G\') format(\'svg\');\n    font-weight: normal;\n    font-style: normal;\n\n}\n\n@font-face {\n    font-family: \'DroidSansMono\';\n    src: url(\'font/DroidSans-Mono-webfont.eot?\') format(\'eot\'),\n         url(\'font/DroidSans-Mono-webfont.woff\') format(\'woff\'),\n         url(\'font/DroidSans-Mono-webfont.ttf\') format(\'truetype\'),\n         url(\'font/DroidSans-Mono-webfont.svg#webfontSOhoM6aS\') format(\'svg\');\n    font-weight: normal;\n    font-style: normal;\n\n}\n\n@font-face {\n    font-family: \'DroidSerif\';\n    src: url(\'font/DroidSerif-webfont.eot?\') format(\'eot\'),\n         url(\'font/DroidSerif-webfont.woff\') format(\'woff\'),\n         url(\'font/DroidSerif-webfont.ttf\') format(\'truetype\'),\n         url(\'font/DroidSerif-webfont.svg#webfontw7zqO19G\') format(\'svg\');\n    font-weight: normal;\n    font-style: normal;\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后在您的代码中,您的 font-family 应该与您在上面的 css 中声明的相同(即 font-family: \'Droid Sans\'; 与 font-family: \'DroidSans\' 不同)

\n\n
<p style=\'font-family: "DroidSans",sans-serif;\'>v\xc3\xa2nd whisky \xc8\x99i tequila, pre\xc8\x9b fix.</p>\n<p style=\'font-family: "DroidSansMono",monospace;\'>v\xc3\xa2nd whisky \xc8\x99i tequila, pre\xc8\x9b fix.</p>\n<p style=\'font-family: "DroidSerif",serif;\'>v\xc3\xa2nd whisky \xc8\x99i tequila, pre\xc8\x9b fix.</p>\n
Run Code Online (Sandbox Code Playgroud)\n\n

尝试一下,看看你进展如何。

\n

  • 我不想使用自定义字体,而只是尝试使用浏览器提供的字体。 (6认同)