如何将fonts.ttf文件添加到grails项目

如何将fonts.ttf文件添加到grails项目,grails,fonts,grails-controller,Grails,Fonts,Grails Controller,我有自定义字体文件。如何将其添加到grails项目中。我可以使用${resource(dir:,file:“”)}来添加它吗?这个答案不限于Grails,因为您使用CSS来实现它,这说明你需要这样做 您可以使用相对路径,并让Grails资源为您处理: 将您的字体放入web app/fonts(创建目录) 添加到您的css(考虑文件Delicious-Roman.ttf,替换为您的): 从任何网站下载你的字体。 一定要。 它将生成一个zip文件。在其中,您可以访问.css文件,并在样式标记内复制和

我有自定义字体文件。如何将其添加到grails项目中。我可以使用${resource(dir:,file:“”)}来添加它吗?

这个答案不限于Grails,因为您使用CSS来实现它,这说明你需要这样做

您可以使用相对路径,并让Grails资源为您处理:

将您的字体放入web app/fonts(创建目录)

添加到您的css(考虑文件Delicious-Roman.ttf,替换为您的):


从任何网站下载你的字体。 一定要。 它将生成一个zip文件。在其中,您可以访问.css文件,并在样式标记内复制和粘贴web中的代码。还将所有文件粘贴到同一目录中。它将运行所有浏览器

@font-face {
font-family: 'Philosopher';
src: url('WebRoot/fonts/philosopher-regular.eot');
src: url('WebRoot/fonts/philosopher-regular.eot?#iefix') format('embedded-opentype'),
     url('WebRoot/fonts/philosopher-regular.woff') format('woff'),
     url('WebRoot/fonts/philosopher-regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}

body{
font-size: 13px;
    font-family: "Philosopher";
}
此代码段适用于philospher字体。基于此示例,您可以使用任何字体。
享受。

将其放入
web应用程序中。
您可以创建类似web app/fonts的目录,并将其引用为
/fonts/yourfont.ttf
${resource(dir:'font',file:yourfont.ttf}
请注意,只有在根上下文中运行应用程序时,第一种方法才有效

@font-face {
font-family: 'Philosopher';
src: url('WebRoot/fonts/philosopher-regular.eot');
src: url('WebRoot/fonts/philosopher-regular.eot?#iefix') format('embedded-opentype'),
     url('WebRoot/fonts/philosopher-regular.woff') format('woff'),
     url('WebRoot/fonts/philosopher-regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}

body{
font-size: 13px;
    font-family: "Philosopher";
}