简体   繁体   English

如何在CSS中添加自定义字体?

[英]How to add a custom font in CSS?

I was wondering if, anyone out there could help me figure out how to add a local font from my PC (WIN 10) to my local HTML website. 我想知道是否有人可以帮助我弄清楚如何从PC(WIN 10)向本地HTML网站添加本地字体。 Here is what i have tried so far. 到目前为止,这是我尝试过的。

@font-face {
    font-family: bubble;
    src: local(fonts/bubble.otf);
}

Here I want to take the font from my folder called "fonts" wich is located inside my website's folder and then choose bubble.otf, but it does not work 在这里,我要从名为“ fonts”的文件夹中提取字体,该字体位于我网站的文件夹内,然后选择bubble.otf,但是它不起作用

body {
    margin:0;
    font-family: bubble;
}

在此处输入图片说明

If the font is in your websites folder, you should consider it to be not a local font. 如果字体在您的网站文件夹中,则应将其视为非本地字体。 It's not a locally installed font but a part of your website, even though the website is on your computer. 即使网站位于您的计算机上,它也不是本地安装的字体,而是网站的一部分。

So I think you misunderstood the meaning of local , and you should load the font as if it is a normal web font, using url instead of local . 因此,我认为您误解了local的含义,应该使用url而不是local来加载字体,就好像它是普通的网络字体一样。

If you want to call your fonts from your local directory, you have to call it using the "url" instead of local as you used. 如果要从本地目录调用字体,则必须使用“ url”而不是您以前使用的本地字体来调用它。 Below is a workable example of what you want to achieve. 以下是您想要实现的可行示例。

@font-face {
font-family: Segoel;
src: url('../font/segoel.eot'); /* IE9 Compatibility Modes */
src: url('../font/segoel.eot?') format('eot'),  /* IE6-IE8 */
url('../font/segoel.woff') format('woff'), /* Modern Browsers */
url('../font/segoel.ttf')  format('truetype'), /* Safari, Android, iOS */
url('../font/segoel.svg#svgsegoel') format('svg'); /* Legacy iOS */  }

However, linking to online font repositories such as Google font , fontsquirrel directly are most effective ways especially when you want to use variety of fonts. 但是,直接链接到在线字体存储库(例如Google fontfontsquirrel)是最有效的方法,尤其是当您要使用各种字体时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM