Using @font-face with Rails 3.1 app?

前端 未结 7 1815
青春惊慌失措
青春惊慌失措 2020-12-02 08:23

I\'m having trouble using the following @font-face declaration to work with my Rails 3.1 app. I put the fonts in the Asset Pipeline in its own folder called \"

7条回答
  •  悲&欢浪女
    2020-12-02 09:13

    From Rails 3.1 and above you can call font-url directly. Like this:

    @font-face {
      font-family: 'ChunkFiveRegular';
      src: font-url('Chunkfive-webfont.eot');
      src: font-url('Chunkfive-webfont.eot?#iefix') format('embedded-opentype'),
         font-url('Chunkfive-webfont.woff') format('woff'),
         font-url('Chunkfive-webfont.ttf') format('truetype'),
         font-url('Chunkfive-webfont.svg#ChunkFiveRegular') format('svg');
      font-weight: normal;
      font-style: normal;
    }
    

    Expect your final css to look like that:

    @font-face {
      font-family: 'ChunkFiveRegular';
      src: url(/assets/Chunkfive-webfont.eot);
      src: url(/assets/Chunkfive-webfont.eot?#iefix) format('embedded-opentype'),
         url(/assets/Chunkfive-webfont.woff) format('woff'),
         url(/assets/Chunkfive-webfont.ttf) format('truetype'),
         url(/assets/Chunkfive-webfont.svg#ChunkFiveRegular) format('svg');
      font-weight: normal;
      font-style: normal;
    }
    

    Usually works :)

提交回复
热议问题