Php CSS@font-face自定义字体不';如果字体源为,则无法工作http://xxx

Php CSS@font-face自定义字体不';如果字体源为,则无法工作http://xxx,php,html,css,Php,Html,Css,因此,我的问题是,当我将这些自定义字体添加到单独的.css文件中并将其包括在下面时,这些自定义字体不起作用: <link rel="stylesheet" href="http://lib.mywebsite.eu/content/content.css"> <style type='text/css'> @font-face { font-family: 'JosefinSansThin'; src: url('/subdom/lib/content/font

因此,我的问题是,当我将这些自定义字体添加到单独的.css文件中并将其包括在下面时,这些自定义字体不起作用:

<link rel="stylesheet" href="http://lib.mywebsite.eu/content/content.css">
<style type='text/css'>
    @font-face {
font-family: 'JosefinSansThin';
src: url('/subdom/lib/content/fonts/JosefinSansThin.eot');
src: url('/subdom/lib/content/fonts/JosefinSansThin.eot') format('embedded-opentype'),
    url('/subdom/lib/content/fonts/JosefinSansThin.woff2') format('woff2'),
    url('/subdom/lib/content/fonts/JosefinSansThin.woff') format('woff'),
    url('/subdom/lib/content/fonts/JosefinSansThin.ttf') format('truetype'),
    url('/subdom/lib/content/fonts/JosefinSansThin.svg#JosefinSansThin') format('svg');}</style>
因此,我尝试将整个css复制到html文件中,如下所示:

<link rel="stylesheet" href="http://lib.mywebsite.eu/content/content.css">
<style type='text/css'>
    @font-face {
font-family: 'JosefinSansThin';
src: url('/subdom/lib/content/fonts/JosefinSansThin.eot');
src: url('/subdom/lib/content/fonts/JosefinSansThin.eot') format('embedded-opentype'),
    url('/subdom/lib/content/fonts/JosefinSansThin.woff2') format('woff2'),
    url('/subdom/lib/content/fonts/JosefinSansThin.woff') format('woff'),
    url('/subdom/lib/content/fonts/JosefinSansThin.ttf') format('truetype'),
    url('/subdom/lib/content/fonts/JosefinSansThin.svg#JosefinSansThin') format('svg');}</style>

@字体{
字体系列:“josefinansthin”;
src:url('/subdom/lib/content/font/josefinansthin.eot');
src:url('/subdom/lib/content/fonts/JosefinSansThin.eot')格式('embedded-opentype'),
url('/subdom/lib/content/font/josefinansthin.woff2')格式('woff2'),
url('/subdom/lib/content/font/josefinansthin.woff')格式('woff'),
url('/subdom/lib/content/font/josefinansthin.ttf')格式('truetype'),
url('/subdom/lib/content/font/josefinansthin.svg#josefinansthin')格式('svg');}
轰!成功了。 但我不想只在index.php中使用它,我需要它在其他html/php文件中-->它需要在外部文件中。因此,我的下一个尝试是将其包含在php中:

<style type='text/css'>
    <?php
        include $_SERVER['DOCUMENT_ROOT'].'/subdom/lib/content/content.css';
    ?>
</style>

它工作了,但由于include works的方式,在外部css中,字体的路径必须与index.php-“/subdom/lib/content/fonts…”中的相同,因此我不能在根目录以外的其他文件夹中使用它。 如果我能指出它的地址(等于)就好了
知道它为什么不起作用吗?谢谢

您需要使CSS文件本身中的链接成为绝对链接:

@font-face {
font-family: 'JosefinSansThin';
src: url('/subdom/lib/content/fonts/JosefinSansThin.eot');
src: url('/subdom/lib/content/fonts/JosefinSansThin.eot') format('embedded-opentype'),
    url('/subdom/lib/content/fonts/JosefinSansThin.woff2') format('woff2'),
    url('/subdom/lib/content/fonts/JosefinSansThin.woff') format('woff'),
    url('/subdom/lib/content/fonts/JosefinSansThin.ttf') format('truetype'),
    url('/subdom/lib/content/fonts/JosefinSansThin.svg#JosefinSansThin') format('svg');
使链接成为绝对链接将允许它们工作,而不管您在哪个文件夹中


希望这有帮助

您需要使CSS文件本身中的链接成为绝对链接:

@font-face {
font-family: 'JosefinSansThin';
src: url('/subdom/lib/content/fonts/JosefinSansThin.eot');
src: url('/subdom/lib/content/fonts/JosefinSansThin.eot') format('embedded-opentype'),
    url('/subdom/lib/content/fonts/JosefinSansThin.woff2') format('woff2'),
    url('/subdom/lib/content/fonts/JosefinSansThin.woff') format('woff'),
    url('/subdom/lib/content/fonts/JosefinSansThin.ttf') format('truetype'),
    url('/subdom/lib/content/fonts/JosefinSansThin.svg#JosefinSansThin') format('svg');
使链接成为绝对链接将允许它们工作,而不管您在哪个文件夹中


希望这有帮助

URL不应该是:

?

CSS文件中的相对URL是相对于文件位置的

url('font/josefinansthin.eot')
位于
http://lib.mywebsite.eu/content/content.css
相当于
http://lib.mywebsite.eu/content/fonts/JosefinSansThin.eot


更新:如果出现最坏的情况,只需使用绝对路径。

URL不应该是:

?

CSS文件中的相对URL是相对于文件位置的

url('font/josefinansthin.eot')
位于
http://lib.mywebsite.eu/content/content.css
相当于
http://lib.mywebsite.eu/content/fonts/JosefinSansThin.eot


更新:如果出现最坏的情况,只需使用绝对路径即可。

这就是我现在使用的方法,我使用PHP的include将其包含到index.PHP中。但若我在php中使用它,但它不在主文件夹中(例如on),它将无法工作,因为地址。。。不存在。这不应该发生——初始斜杠表示根。如果你引用它,它应该引用。天哪,我太笨了!Ofc。我没有绝对的链接。。。谢谢你的帮助,我感到很尴尬哈哈不用担心——很高兴你解决了这个问题!:)这就是我现在拥有它的方式,我使用PHP的include将它包含到index.PHP中。但若我在php中使用它,但它不在主文件夹中(例如on),它将无法工作,因为地址。。。不存在。这不应该发生——初始斜杠表示根。如果你引用它,它应该引用。天哪,我太笨了!Ofc。我没有绝对的链接。。。谢谢你的帮助,我感到很尴尬哈哈不用担心——很高兴你解决了这个问题!:)否,我在根目录中有一个目录/subdom,重定向到.htaccess的.htaccess可在此处找到:否,我在根目录中有一个目录/subdom,重定向到.htaccess的.htaccess可在此处找到: