链接到站点之间的Glyphicon字体(Bootstrap)

时间:2015-01-26 00:43:01

标签: css twitter-bootstrap

我正在学习使用Bootstrap。由于我有几个网站,我想在一个网站上放置Boostrap样式表 - bootstrap.css和bootstrap.min.css(" mysite.com")并链接其他网站他们。

问题在于,当我这样做时,我的字形不显示。我发现了名为" fonts,"的文件夹。并将其复制到mysite.com。然后我在bootstrap.min.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')}

事实上,看起来这些是我需要改变的唯一两个:

url(../fonts/glyphicons-halflings-regular.woff) format('woff'),
url(../fonts/glyphicons-halflings-regular.ttf) format('truetype'),

但我还没有能够重写链接以使它们正常工作。例如,网址(http://mysite/css/bootstrap/fonts/glphicons(etc.)无效。

是否可以跨站点链接到glyphicon字体?如果没有,另一种可能性是我可以将样式表放在mysite.com上,但将字体复制到每个站点,然后将这些样式放在每个页面的头部,我可以指向正确的目录。

1 个答案:

答案 0 :(得分:1)

字体文件受跨域访问控制的约束。您需要将字体文件放在每个网站中。停用托管字体文件的服务器上的跨域访问控制。或者配置托管字体文件的服务器以允许您的站点的域访问。

对于apache,您需要在apache主配置文件中设置一些设置,或者在.htaccess中为设置字体文件的域设置一些设置。您必须修改以下内容才能适合您的网站。您需要将mod_headers apache模块加载或编译到服务器中。

这将设置字体文件的内容类型和编码。

AddType font/truetype .ttf
AddType font/opentype .otf
AddType font/opentype .woff
AddType application/vnd.ms-fontobject .eot 
AddType image/svg+xml .svg .svgz
AddEncoding gzip .svgz

这将访问控制设置为允许来自" sample.com"

的访问
<FilesMatch "\.(ttf|otf|eot|woff|svg)$">
 <IfModule mod_headers.c>
  Header set Access-Control-Allow-Origin "sample.com"
 </IfModule>
</FilesMatch>

当然,不同的浏览器的行为会有所不同,因此始终可以在所有浏览器中测试这些更改。对于Apache以外的服务器,您必须使用他们的配置执行与上述相同的操作。

替换&#34; sample.com&#34;通过您网站的网址,您还可以替换&#34; sample.com&#34;使用&#34; *&#34;但是这样做会停用字体文件的控件。它会打开您的服务器,将这些文件提供给可能尝试访问它们的任何其他站点。