我下载了引导3.0,但无法让象形文字工作。我得到一些"E003"错误。知道为什么会这样吗?我在本地和网上都试过了,还是遇到同样的问题。
当前回答
您必须按以下顺序设置:
<link rel="stylesheet" href="path/bootstrap.min.css">
<style type="text/css">
@font-face {
font-family: 'Glyphicons Halflings';
src: url('../fonts/glyphicons-halflings-regular.eot');
src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons-halflingsregular') format('svg');
}
</style>
其他回答
我也遇到了同样的问题,浏览器无法找到字体文件,我的问题是由于我的.htaccess文件中排除了不应该发送到index.php进行处理的白名单文件。由于字体文件无法加载,字符被BLOB替换。
RewriteCond %{REQUEST_URI} !\.(jpg|png|gif|svg|css|js|ico|rss|xml|json)$
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^ index.php [L,QSA]
如您所见,像图像、rss和xml这样的文件被排除在重写之外,但是字体文件是.woff和.woff2文件,因此这些文件也需要添加到白名单中。
RewriteCond %{REQUEST_URI} !\.(jpg|png|gif|svg|css|js|ico|rss|xml|json|woff|woff2)$
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^ index.php [L,QSA]
将woff和woff2添加到白名单中可以加载字体文件,并且字形应该正确显示。
以下是官方文件中关于字体不渲染的说明。
更改图标字体位置 引导程序假定图标字体文件将位于../fonts/目录,相对于编译的CSS文件。移动或重命名这些字体文件意味着以以下三种方式之一更新CSS: 更改源Less文件中的@icon-font-path和/或@icon-font-name变量。 利用Less编译器提供的相对url选项。 修改编译后的CSS中的url()路径。 使用任何最适合您特定开发设置的选项。
除此之外,它可能是你错过了复制字体文件夹到根目录
这是由于bootstrap.css和bootstrap.min.css中的错误编码。当你从定制器下载Bootstrap 3.0时,以下代码是缺失的:
@font-face {
font-family: 'Glyphicons Halflings';
src: url('../fonts/glyphicons-halflings-regular.eot');
src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons-halflingsregular') format('svg');
}
因为这是使用Glyphicons的主要代码,所以它不会在ofc…
从完整的包中下载css文件,这段代码将被实现。
如果其他解决方案不起作用,您可能希望尝试从外部源导入Glyphicons,而不是依赖Bootstrap为您完成所有工作。这样做:
你可以在HTML中这样做:
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" rel="stylesheet">
或CSS:
@import url("//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css")
来自这个线程的信用edsiofi: Bootstrap 3 Glyphicons CDN
我正在使用Angular2和SCSS,作为一个最佳实践,我复制到我的项目中,只有我正在修改的引导文件从node_modules导入。唯一的问题是glyphicon。 经过多次尝试,我发现对我来说最好的解决方案是复制字体文件到我的项目,并直接设置此路径为$ icon-font-path,如图所示: