@page "/"
<style>
@import url('https://fonts.googleapis.com/css2?family=Work+Sans');
body {
margin: 0;
font-family: 'Work Sans';
color: #4d4d4d;
}
</style>
Run Code Online (Sandbox Code Playgroud)
在 React.js 中,我可以简单地使用 @import to use 标签来使用 Google Font,但在 Blazor 中我收到了错误The name 'import' does not exist in current context。在 Blazor 应用程序中全局使用 Google Font 的正确方法是什么?
@用于为 Razor 代码添加前缀,因此您需要使用第二个@. 尝试:
. . .
<style>
@@import url('https://fonts.googleapis.com/css2?family=Work+Sans');
. . .
Run Code Online (Sandbox Code Playgroud)
或者,如果您希望将其本地化到单个页面,请使用CSS-Isolation:
@.