【问题标题】:How to change the font & color when using Html.TextAreaFor?使用 Html.TextAreaFor 时如何更改字体和颜色?
【发布时间】:2011-02-24 02:15:41
【问题描述】:

我使用下面的代码来显示一些文字,它不会改变字体颜色,有人知道为什么吗?

<%= Html.TextAreaFor(m => m.Component.ApplicationDescription, new { cols = "40%", Style = new Style { ForeColor = Color.Red } })%>

【问题讨论】:

  • 使用 CSS 类 .. 更好

标签: asp.net html asp.net-mvc


【解决方案1】:
<%= Html.TextAreaFor(m => m.Component.ApplicationDescription, 
    new { cols = "40%", style = "color:red;" })%>

或应用 css 样式:

<%= Html.TextAreaFor(m => m.Component.ApplicationDescription, 
    new { cols = "40%", @class = "foo" })%>

可能看起来像这样:

.foo {
    color: red;
}

【讨论】:

  • 或在Style = new Style { ForeColor = Color.Red } 中使用{}??!
  • @jjj,使用 Style = new Style { ForeColor = Color.Red } 将生成以下 HTML:Style="System.Web.UI.WebControls.Style",这与浏览器认为的有效 HTML 相差甚远。
  • 现在我很好奇 - 有没有办法以这种方式使用强类型样式?会很好。谢谢
猜你喜欢
  • 1970-01-01
  • 2011-09-27
  • 2020-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-13
  • 2015-05-18
  • 2011-05-20
相关资源
最近更新 更多