代码之家  ›  专栏  ›  技术社区  ›  Ronald LaPlante

在css中查找字体

  •  0
  • Ronald LaPlante  · 技术社区  · 7 年前

    所以我很难正确地获取字体的来源。 我的 public_html ,则, index.php 它使用存储在比html高一个目录的文件夹中的样式表,通过子域访问它。

    除了字体以外,一切都正常。这些字体存储在与样式表相同的webroot中,除了在 fonts

    我应该用一个绝对URL来获取它们,还是我的css有什么问题?

    编辑: 我有一张背景图片 url() 在css中,工作方式相同,并且它的功能很好。

    body {
      background: url('img/bg.png') no-repeat center center fixed;
      font-family: typewriter;
    }
    
    /* -- FONT DEFINITIONS -- */
    @font-face {
      font-family: code;
      src: url('font/code.ttf') format('truetype');
    }
    
    l33tContainer .font1 {
      font-family: code;
    }
    
    @font-face {
      font-family: typewriter;
      src: url('font/typewriter.ttf') format('truetype');
    }
    
    l33tContainer .font2 {
      font-family: typewriter;
    }
    /* END FONT DEFINITIONS */
    
    2 回复  |  直到 7 年前
        1
  •  0
  •   user4095424 user4095424    7 年前

    你能这样试试吗

    @font-face {
    font-family: typewriter;
    src: url('../font/typewriter.ttf') format('truetype');
    }
    

    并确保“l33tContainer”具有类(.),或id(#) 一定是这样。l33tContainer或#l33tContainer

        2
  •  0
  •   Ronald LaPlante    7 年前

    我找到了一个帮助我的解决方案。

    将此添加到 .htaccess 保存字体的子域目录修复了此问题。

    <FilesMatch "\.(ttf|ttc|otf|eot|woff)$">
    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
    </IfModule>
    </FilesMatch>
    

    Original StackOverflow Post