【问题标题】:Setting @Font-Face From C# Code Behind从 C# 代码后面设置@Font-Face
【发布时间】:2018-01-24 21:31:17
【问题描述】:

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

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

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

row.CssClass = light;

但是我得到一个编译错误

当前上下文中不存在名称“light”

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

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

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


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

row.CssClass = lightfontface;

【问题讨论】:

  • 为什么在代码后面而不是在 HTML 中引用样式表?只是问
  • @trebleCode - 因为这是用于在导出为 pdf 时格式化 RadGrid - 不需要在页面上直观地显示它,只需要以这种方式格式化即可导出

标签: c# css asp.net font-face


【解决方案1】:

我相信你的

row.CssClass = light;

需要

row.CssClass = "className";

您的 css 将需要一个 .className 条目。

想象一下你的 html 行:

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

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

总结一些cmets,样式表条目应该是:

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

样式表上的顺序很重要。将 font-face 定义放在 .className 样式条目之上。见:https://www.w3.org/TR/CSS2/cascade.html#cascading-order

【讨论】:

  • 如何在我的 stylesheet.css 中定义它?如果我尝试添加 .classnametest {@font-face { font-family: 'light'; src: url('Fonts/HelveticaNeueLTStd-Lt.otf') 格式('opentype'); } } 我在样式规则中看到了意外的 @ 块视觉错误
  • 你的类的css条目不需要@font-face定义
  • 我试图添加一个像这样的 .className 条目 .lightfontface { font-family: 'light'; - 但如果我尝试从我的 C# 调用 lightfontface,我会得到一个编译错误,即“lightfontface”在当前上下文中不存在
  • 你是如何从 C# 中“调用”它的?在 C# 中,CssClass = "stringValue"。您在之前评论中的 .lightfontface 条目是您的 css 样式表中应该包含的内容
  • @BoJackHorseman 不,看来您没有关注他,哈哈。通过字符串设置类而不是变量。在 css 中制定你的规则..
猜你喜欢
  • 1970-01-01
  • 2016-07-06
  • 2015-05-20
  • 2011-04-06
  • 1970-01-01
  • 2013-03-12
  • 2014-08-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多