从后面的 C# 代码设置 @Font-Face

Setting @Font-Face From C# Code Behind

在我的样式表中我声明了这个

@font-face {
    font-family: 'light';
    src: url('Fonts/HelveticaNeueLTStd-Lt.otf') format('opentype');
}

现在在我后面的 C# 代码中,我尝试像这样设置 class

row.CssClass = light;

但是我得到一个

的编译错误

The name 'light' does not exist in the current context

是否可以从 C# 代码隐藏中引用 css class @font-face?

编辑
这就是我尝试使用它的方式 - 我已经尝试了以下

.lightfontface {
    font-family: 'light';
}


@font-face {
    font-family: 'light';
    src: url('Fonts/HelveticaNeueLTStd-Lt.otf') format('opentype');
}

row.CssClass = lightfontface;

我相信你的

row.CssClass = light;

需要

row.CssClass = "className";

并且您的 css 将需要一个 .class 名称条目。

想象一下您的 html 行:

<tr class="className">stuff</tr>

您的 CssClass 分配正在将值分配给 class,并且您的 css 可以使用 class 选择器来格式化该行。

总结一些评论,样式 sheet 条目应该只是:

.className { font-family: 'light'; }

按您的风格排序 sheet 很重要。将字体定义放在 .className 样式条目之上。参见:https://www.w3.org/TR/CSS2/cascade.html#cascading-order