问题描述
我在Visual Studio 2017中开发了一个C#.NET应用程序。我试图从.ttf文件导入新字体。我将文件放在assets / fonts / Futura.ttf。然后,我尝试使用CSS像这样导入它:
@section Styles {
<style>
...
@font-face {
font-family: "Futura";
src: url("assets/fonts/Futura.ttf") format("TrueType"),}
...
</style>
}
error CS0103: The name 'font' does not exist in the current context
问题所在行显示:@ font-face {
有人知道为什么它不理解@ font-face吗?只是一个.cshtml文件。
谢谢
解决方法
您可以尝试以下cshtml代码使用ttf文件中的新字体。
请在字体前添加两个'@'。
<!DOCTYPE html>
<html>
<head>
<style>
@@font-face {
font-family: "Font Name";
src: url("../fonts/OpenSans-BoldItalic.ttf");
}
.testfont { font-family: 'Font Name'; }
</style>
<title>test111</title>
</head>
<body>
<P class="testfont" >Hello,world</P>
</body>
</html>
结果: