[英]Bootstrap glyphicons aren't appearing when using Rails 5 and bootstrap-sass gem
Glyphicons from bootstrap aren't showing up on my site. 引导程序产生的Glyphicons没有出现在我的网站上。 I went to check the Network
tab in chrome dev tools and saw requests like this for the fonts: 我去检查了chrome开发工具中的“ Network
标签,看到了这样的字体请求:
Request URL:http://localhost:3000/fonts/bootstrap/glyphicons-halflings-regular.woff2
Request Method:GET
Status Code:404 Not Found
So I grab the glyphicon fonts and place them in app/assets/fonts/bootstrap
, but that doesn't work. 所以我抓住了glyphicon字体,并将它们放在app/assets/fonts/bootstrap
,但这是行不通的。 I moved the fonts/
folder to public/
and tried again. 我将fonts/
文件夹移到public/
然后重试。 Glyphicons worked, but this just seems like bad practice. Glyphicons起作用了,但这似乎是一种不好的做法。
How do I keep the fonts in app/assets/fonts
and get them to load right? 如何将字体保留在app/assets/fonts
并正确加载?
As I was writing the question, I figured it out. 当我写这个问题时,我发现了。
In your bootstrap theme file, look for these lines: 在您的引导程序主题文件中,查找以下几行:
//== Iconography
//
//## Specify custom location and filename of the included Glyphicons icon font. Useful for those including Bootstrap via Bower.
//** Load fonts from this directory.
// [converter] If $bootstrap-sass-asset-helper if used, provide path relative to the assets load path.
// [converter] This is because some asset helpers, such as Sprockets, do not work with file-relative paths.
$icon-font-path: if($bootstrap-sass-asset-helper, "bootstrap/", "../fonts/bootstrap/");
I changed the variable $icon-font-path
so it looks like this: 我更改了变量$icon-font-path
所以它看起来像这样:
$icon-font-path: if($bootstrap-sass-asset-helper, "bootstrap/", "../assets/fonts/bootstrap/");
Note: all the glyphicon font files are present in app/assets/fonts/bootstrap
注意:所有glyphicon字体文件都存在于app/assets/fonts/bootstrap
我建议您使用: font-awesome-sass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.