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

标签 c# css asp.net font-face

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

@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/

相关文章:

asp.net - 如何在 Asp.net 中使用 GZIP 文件?

html - 如何将无序 block 列表居中

css - DIV之间存在差距的原因是什么

html - 自定义下拉菜单将内容向下推

javascript - 在 Telerik RadPageView 完成加载后调用 JavaScript 函数?

asp.net - IIS 6 的服务器.TransferRequest

c# - 难以理解异步和等待

c# - 为多个参数创建唯一键(缓存键)

c# - 有没有办法告诉 WCF 服务有多少个 "Concurrent Calls"?

c# - 在 C# 中检测(通过反射)枚举是否为 "Flags"类型的策略