热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

为什么font-awesome可以在本地主机上工作,而不能在web上工作?-Whyfont-awesomeworksonlocalhostbutnotonweb?

Imusingfontawesomeinmyproject(mvcasp.net).Myproblemis,Iwasdebuggingtheprojectandch

I'm using font awesome in my project(mvc/asp.net). My problem is, I was debugging the project and check on localhost, there was no problem with font awesome icons. But when published the website and check on web, instead of icons, i saw small boxes. I'm sure that it's placed in right directory(where css files placed).

我在我的项目(mvc/asp.net)中使用的字体很棒。我的问题是,我正在调试项目并检查localhost,字体很棒的图标没有问题。但当我发布网站并在网上查看时,我看到的不是图标,而是小盒子。我确信它被放在了正确的目录(css文件所在的位置)。

I couldn't find any proper solution.

我找不到合适的解决办法。

By the way there is also no problem with buttons. They are all ok but icons are gone.

顺便说一下,按钮也没有问题。它们都没问题,但是图标都没了。

Thanks

谢谢

9 个解决方案

#1


59  

I've just loaded your webpage and checked the net tab of firebug.

我刚刚加载了你的网页并检查了firebug的net选项卡。

your following urls returned a 404:

您的下列网址返回404:

http://www.senocakonline.com/Content/font/fontawesome-webfont.woff

http://www.senocakonline.com/Content/font/fontawesome-webfont.woff

http://www.senocakonline.com/Content/font/fontawesome-webfont.ttf

http://www.senocakonline.com/Content/font/fontawesome-webfont.ttf

i would assume that those being missing is the reason your icons aren't displaying.

我认为那些丢失的是你的图标不显示的原因。

UPDATE: 23.10.2015 to make it available just add this code to your WebConfig:

更新:23.10.2015要使其可用,只需将此代码添加到您的WebConfig中:


    
      
      
    

#2


33  

Why font-awesome works on debug mode but not on IIS?

为什么在调试模式下,而不是在IIS上,为什么会有很棒的工作呢?

In Visual Studio, by default, some font files are not including during Publish:

在Visual Studio中,默认情况下,有些字体文件在发布期间不包含:

  • .eot
  • .eot
  • .json
  • . json
  • .ttf
  • .ttf
  • .woff
  • .woff

This is because their build action is set to None, this is by default (on MVC, not sure on WebForms). You must go to the affected file's properties and set it from "None" to "Content".

这是因为他们的构建操作被设置为None,这是默认的(在MVC上,在WebForms上不确定)。您必须访问受影响文件的属性,并将其从“None”设置为“Content”。

enter image description here

This is how I solved it (not by manually dragging the files as some may suggest)

这就是我解决它的方法(不是像有些人建议的那样手动拖拽文件)

Credits goes to this guy: http://edsykes.blogspot.com/2012/09/aspnet-build-actions-with-ttf-eot-and.html

值得称道的是:http://edsykes.blogspot.com/2012/09/aspnet build-action -with-ttf-eot-and.html

#3


8  

I had the same problem. The solution:

我也有同样的问题。解决方案:

  1. Open CSS file and delete the current font-face section and replace with these:

    打开CSS文件,删除当前字体部分,并替换为:

    @font-face {
    
        font-family: FontAwesome;
        src: url('/Content/fonts/fontawesome-webfont.eot'), /*for IE */
             url('/Content/fonts/fontawesomewebfont.svg'),
             url('/Content/fonts/fontawesome-webfont.ttf'); /* for CSS3 browsers */
        font-weight: normal;
        font-style: normal;
    }
    

    (change the font-face values as you want)

    (根据需要更改字体值)

  2. Copy your ttf font file on your desktop then convert to eot

    在桌面上复制ttf字体文件,然后转换为eot

    http://www.kirsle.net/wizards/ttf2eot.cgi

    http://www.kirsle.net/wizards/ttf2eot.cgi

  3. Convert ttf font file to svg

    将ttf字体文件转换为svg

    http://www.freefontconverter.com/

    http://www.freefontconverter.com/

  4. Convert ttf font file to woff (optional)

    将ttf字体文件转换为woff(可选)

    http://ttf2woff.com/

    http://ttf2woff.com/

  5. Drag and drop these all fonts (ttf, eot, svg, woff... ) to your file location when Visual Studio 2012 is open.

    拖放这些字体(ttf、eot、svg、woff…)当Visual Studio 2012打开时,将其发送到您的文件位置。

  6. Publish your project

    发布您的项目

#4


7  

Another solution that solved this issue for me can be found here: https://stackoverflow.com/a/12587256/615285

另一个解决这个问题的解决方案可以在这里找到:https://stackoverflow.com/a/12587256/615285

Quoting from there:

引用:

The issue is most likely that the icons/images in the css files are using relative paths, so if your bundle doesn't live in the same app relative path as your unbundled css files, they become broken links.

问题很可能是css文件中的图标/图像使用的是相对路径,因此,如果您的bundle与未绑定的css文件不在同一个应用程序的相对路径中,那么它们将成为断开的链接。

The easist thing to do is to have your bundle path look like the css directory so the relative urls just work, i.e:

最简单的做法是让你的bundle路径看起来像css目录,这样相对url就可以工作了,例如:

new StyleBundle("~/Static/Css/bootstrap/bundle")

We have added support for this in the 1.1beta1 release, so to automatically rewrite the image urls, you can add a new ItemTransform which does this rebasing automatically.

我们在1.1beta1版本中添加了对它的支持,因此要自动重写图像url,您可以添加一个新的ItemTransform,该转换可以自动地进行重设。

bundles.Add(new StyleBundle("~/bundles/publiccss").Include(
            "~/Static/Css/bootstrap/bootstrap.css",
            "~/Static/Css/bootstrap/bootstrap-padding-top.css",
            "~/Static/Css/bootstrap/bootstrap-responsive.css",
            "~/Static/Css/bootstrap/docs.css", new CssRewriteUrlTransform()));

#5


2  

It depends on this code line in BundleConfig:

这取决于BundleConfig中的代码行:

        BundleTable.EnableOptimizatiOns= true;

if it is true, you have to change your Font files's path;

如果这是真的,你必须改变字体文件的路径;

../ is shows root path, main folder of your project. And then you have to write rest of the path.

. ./显示您的项目的主文件夹根路径。然后你要写下剩下的路径。

Mine. When it's true:

我的。当这是真的:

font-family: 'Icons';
    src:url('../_include/css/fonts/Icons.eot');
    src:url('../_include/css/fonts/Icons.eot?#iefix') format('embedded-opentype'),
        url('../_include/css/fonts/Icons.woff') format('woff'),
        url('../_include/css/fonts/Icons.ttf') format('truetype'),
        url('../_include/css/fonts/Icons.svg#Icons') format('svg');
    font-weight: normal;
    font-style: normal;

When it's false:

当它是错误的:

font-family: 'Icons';
    src:url('fonts/Icons.eot');
    src:url('fonts/Icons.eot?#iefix') format('embedded-opentype'),
        url('fonts/Icons.woff') format('woff'),
        url('fonts/Icons.ttf') format('truetype'),
        url('fonts/Icons.svg#Icons') format('svg');
    font-weight: normal;
    font-style: normal;

#6


1  

It is also a MIME TYPE problem in the IIS, just add the file extension .woff and it will work

这也是IIS中的MIME类型问题,只要添加文件扩展名.woff就可以了

#7


1  

this worked for me :

这对我起了作用:

I had to link the Directly URl

我必须直接链接URl

#8


0  

In my ASP.NET MVC project with bundling enabled in BundleConfig.cs what worked was this:

在我的ASP。NET MVC项目在BundleConfig中启用绑定。cs有效的是:

Open the file font-awesome.css and change @font-face to this:

font-awesome打开文件。css和change @font-face:

@font-face {
  font-family: 'FontAwesome';
  src: url('../font/fontawesome-webfont.eot?v=3.2.1');
  src: url('../font/fontawesome-webfont.eot?#iefix&v=3.2.1') format('embedded-opentype'), url('../font/fontawesome-webfont.woff?v=3.2.1') format('woff'), url('../font/fontawesome-webfont.ttf?v=3.2.1') format('truetype'), url('../font/fontawesome-webfont.svg#fontawesomeregular?v=3.2.1') format('svg');
  font-weight: normal;
  font-style: normal;
}

I had to add ../ before each url.

我不得不加上……/在每个url。

#9


0  

I had the same problem. Fonts were shown on local properly but when I uploded it to server, only blank squares were shown.
Sometimes it may happen because the filename mentioned in FontAwesome CSS file src attribute is different from the actual font file name. In my case I found it like this in fontawesome css file:

我也有同样的问题。字体被正确地显示在本地,但当我把它上传到服务器时,只显示了空白的方块。有时可能会发生,因为在FontAwesome CSS文件src属性中提到的文件名不同于实际的字体文件名。在我的案例中,我在fontawesome css文件中发现的是这样的:


    @font-face {
            font-family: 'FontAwesome';
            src: url('../font/fontawesome-webfont.eot?v=3.2.1');
            src: url('../font/fontawesome-webfont.eot?#iefix&v=3.2.1') format('embedded-opentype'),
                url('../font/fontawesome-webfont.woff?v=3.2.1') format('woff'),
                url('../font/fontawesome-webfont_aea8981c.ttf?v=3.2.1') format('truetype'),
                url('../font/fontawesome-webfont.svg#fontawesomeregular?v=3.2.1') format('svg');
            font-weight: normal;
            font-style: normal;
        }
        

But the actual font file names wese like these-
        font/fontawesome-webfont_2d2816fe.eot
        font/fontawesome-webfont_aea8981c.eot
        font/fontawesome-webfont_aea8981c.ttf
        font/fontawesome-webfont_aea8981c.woff
        

though the name didn't match properly in css file after underscore, it was working fine on local. So it was hard to tell what was the probable cause for that.
When I edited the name of file in FontAwesome css file src to the exact actual names, it worked.

尽管在css文件中,下划线之后的名称并不匹配,但是在本地版本中,它仍然运行良好。所以很难判断出可能的原因是什么。当我将FontAwesome css文件src中的文件名称编辑成确切的实际名称时,它成功了。


推荐阅读
  • 本文介绍了Web学习历程记录中关于Tomcat的基本概念和配置。首先解释了Web静态Web资源和动态Web资源的概念,以及C/S架构和B/S架构的区别。然后介绍了常见的Web服务器,包括Weblogic、WebSphere和Tomcat。接着详细讲解了Tomcat的虚拟主机、web应用和虚拟路径映射的概念和配置过程。最后简要介绍了http协议的作用。本文内容详实,适合初学者了解Tomcat的基础知识。 ... [详细]
  • Nginx使用AWStats日志分析的步骤及注意事项
    本文介绍了在Centos7操作系统上使用Nginx和AWStats进行日志分析的步骤和注意事项。通过AWStats可以统计网站的访问量、IP地址、操作系统、浏览器等信息,并提供精确到每月、每日、每小时的数据。在部署AWStats之前需要确认服务器上已经安装了Perl环境,并进行DNS解析。 ... [详细]
  • Skywalking系列博客1安装单机版 Skywalking的快速安装方法
    本文介绍了如何快速安装单机版的Skywalking,包括下载、环境需求和端口检查等步骤。同时提供了百度盘下载地址和查询端口是否被占用的命令。 ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • 搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的详细步骤
    本文详细介绍了搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的步骤,包括环境说明、相关软件下载的地址以及所需的插件下载地址。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • 本文介绍了Hyperledger Fabric外部链码构建与运行的相关知识,包括在Hyperledger Fabric 2.0版本之前链码构建和运行的困难性,外部构建模式的实现原理以及外部构建和运行API的使用方法。通过本文的介绍,读者可以了解到如何利用外部构建和运行的方式来实现链码的构建和运行,并且不再受限于特定的语言和部署环境。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • 本文介绍了在Windows环境下如何配置php+apache环境,包括下载php7和apache2.4、安装vc2015运行时环境、启动php7和apache2.4等步骤。希望对需要搭建php7环境的读者有一定的参考价值。摘要长度为169字。 ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
  • 本文介绍了如何使用C#制作Java+Mysql+Tomcat环境安装程序,实现一键式安装。通过将JDK、Mysql、Tomcat三者制作成一个安装包,解决了客户在安装软件时的复杂配置和繁琐问题,便于管理软件版本和系统集成。具体步骤包括配置JDK环境变量和安装Mysql服务,其中使用了MySQL Server 5.5社区版和my.ini文件。安装方法为通过命令行将目录转到mysql的bin目录下,执行mysqld --install MySQL5命令。 ... [详细]
  • 本文介绍了Windows操作系统的版本及其特点,包括Windows 7系统的6个版本:Starter、Home Basic、Home Premium、Professional、Enterprise、Ultimate。Windows操作系统是微软公司研发的一套操作系统,具有人机操作性优异、支持的应用软件较多、对硬件支持良好等优点。Windows 7 Starter是功能最少的版本,缺乏Aero特效功能,没有64位支持,最初设计不能同时运行三个以上应用程序。 ... [详细]
  • web.py开发web 第八章 Formalchemy 服务端验证方法
    本文介绍了在web.py开发中使用Formalchemy进行服务端表单数据验证的方法。以User表单为例,详细说明了对各字段的验证要求,包括必填、长度限制、唯一性等。同时介绍了如何自定义验证方法来实现验证唯一性和两个密码是否相等的功能。该文提供了相关代码示例。 ... [详细]
  • phpcomposer 那个中文镜像是不是凉了 ... [详细]
author-avatar
U曹宸prideX_J
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有