在我的样式表中声明了这个
@font-face {
font-family: 'light';
src: url('Fonts/HelveticaNeueLTStd-Lt.otf') format('opentype');
}
现在在我后面的 C# 代码中,我尝试像这样设置类
row.CssClass = light;
但是我得到一个编译错误
The name 'light' does not exist in the current context
是否可以从 C# 代码隐藏中引用 css 类@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 将需要一个 .className 条目。
想象一下您的 html 行:
<tr class="className">stuff</tr>
您的 CssClass 分配是将值分配给类,您的 css 可以使用类选择器来格式化该行。
总结一些评论,样式表条目应该只是:
.className { font-family: 'light'; }
样式表的顺序很重要。将字体定义放在 .className 样式条目之上。请参阅:https://www.w3.org/TR/CSS2/cascade.html#cascading-order
关于c# - 从后面的 C# 代码设置 @Font-Face,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48431923/