Html 如何在服务器中安装字体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3947766/
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
How to install a Font in server
提问by user434770
I have downloaded and installed a font in my system, then i used this font in my project, its worked fine in local system, but when i upload this page to server its not working. How can i install a font in server? or How can i solve this issue?
我已经在我的系统中下载并安装了一种字体,然后我在我的项目中使用了这种字体,它在本地系统中运行良好,但是当我将此页面上传到服务器时它不起作用。如何在服务器中安装字体?或者我该如何解决这个问题?
Please Help me!!!!
请帮我!!!!
回答by flight643
With CSS3 it is possible to embed fonts on websites even if it isn't available on the user's machine.
使用 CSS3 可以在网站上嵌入字体,即使它在用户的机器上不可用。
First upload your font to a directory on your server.
首先将您的字体上传到服务器上的目录。
Then register that font in your CSS so that you can use it like so:
然后在您的 CSS 中注册该字体,以便您可以像这样使用它:
@font-face {
font-family: 'Raspoutine Medium';
src: url(http://site/fonts/Raspoutine Medium.ttf);
}
Then, to use it on elements within your site:
然后,在您网站中的元素上使用它:
body {
font-family: 'Raspoutine Medium', Arial, Helvetica, san-serif;
}
(see http://www.w3.org/TR/css3-fonts/#the-font-face-rule)
(见http://www.w3.org/TR/css3-fonts/#the-font-face-rule)
Note that this will only work in select modern browsers, namely current versions of Firefox, Chrome, Safari, Opera, and IE9. IE8 and older versions of IE don't support this so it's good to declare and test the site with a 'fall back' font.
请注意,这仅适用于部分现代浏览器,即当前版本的 Firefox、Chrome、Safari、Opera 和 IE9。IE8 和旧版本的 IE 不支持此功能,因此最好使用“后备”字体声明和测试站点。
Also note that there may be licensing issues depending on the font..
另请注意,根据字体可能存在许可问题。
回答by Shoban
Even if you install the font in your server it does not mean that the font should work when your users try to access the site. The font has to be installed in all the machines that is going to access it so if your site is public you can't make every user to install the font. So a good practice and recommended method is to use default fonts.
即使您在服务器中安装了该字体,也不意味着当您的用户尝试访问该站点时该字体应该可以工作。该字体必须安装在所有要访问它的机器上,因此如果您的站点是公开的,则不能让每个用户都安装该字体。所以一个好的做法和推荐的方法是使用默认字体。
Another option is to check out Google Fonts API. Advantages are
另一种选择是查看Google Fonts API。优点是
* A choice of high quality open source fonts.
* Works in most browsers.
* Extremely easy to use.
回答by Patty31
First you need to upload your font file to server, download zip file of your font and upload the unziped folder to server via FTP like filezilla then you may use this in you css but replace "font/path" with your path where you are going to upload the font and its not compulsory to upload all extension file given below but it is a good practice to do so if you don't want to upload any extension file just remove its entry from below code
首先,您需要将字体文件上传到服务器,下载字体的 zip 文件,然后通过 FTP(如 filezilla)将解压缩的文件夹上传到服务器,然后您可以在 css 中使用它,但将“字体/路径”替换为您要去的路径上传字体而不强制上传下面给出的所有扩展文件,但如果您不想上传任何扩展文件,那么这样做是一个好习惯,只需从下面的代码中删除其条目
@font-face { font-family: 'Font Name'; src: url('font/path/fontname.eot'); src: url('font/path/fontname.eot?#iefix') format('embedded-opentype'), url('font/path/fontname.woff') format('woff'), url('font/path/fontname.ttf') format('truetype'); font-weight: normal; font-style: normal;}
You can use it like
你可以像这样使用它
#element { font-family: 'Font Name'; }
Hope this helps
希望这可以帮助
回答by David Spector
You can load a font from the server into a web page just like any other resource, using CSS3 for all modern browsers except for IE, which requires using WEFT.exe (download free from Microsoft) to create an EOT file from the TTF font file (store the TTF file in your local fonts directory before running WEFT).
您可以像任何其他资源一样将字体从服务器加载到网页中,对除 IE 之外的所有现代浏览器使用 CSS3,IE 需要使用 WEFT.exe(从 Microsoft 免费下载)从 TTF 字体文件创建 EOT 文件(在运行 WEFT 之前将 TTF 文件存储在本地字体目录中)。
Once you have the TTF and EOT files in your website directory, the following code should work:
一旦您的网站目录中有 TTF 和 EOT 文件,以下代码应该可以工作:
/* Load font for IE only */
@font-face {font-family: Font Name;font-style: normal; font-weight: normal; src: url(FontName.eot)}
/* Load font for other browsers */
@font-face {font-family: Font Name; src: url(FontName.ttf)}
/* Specify default font and any other styles */
#id {font-family:Font Name,sans-serif}
...
<p id="id">Text to be displayed</p>
回答by will
Right-click font you want to install and click Install or Drag font into/onto the Fonts icon in the Control Panel.
右键单击要安装的字体,然后单击安装或将字体拖入/拖到控制面板中的字体图标上。
回答by Amin Saadati
You can use /
for getting relative paths.
您可以/
用于获取相对路径。
@font-face {
font-family: Font-Name;
src: url(/content/font/Font-Name.ttf ); /* IE */
src: local("B Yekan"), url(/Content/fonts/Font-Name.ttf format("truetype"); /* non-IE */
font-style: normal;
font-weight: 100;
}