Asp.Net MVC 覆盖 Class CSS
Asp.Net MVC overriding Class CSS
我有一个 H1 标签,里面有一个从代码生成的锚标签
<div class=".slide-title">
<H1>
@RenderLinkTracking(m => m.btn, Model.bTnTitle)
</H1>
</div>
RenderLinkTracking 创建锚标记
<a href="/home/" data-id="Image Title<">Image Title</a>
锚标签的CSS是
.slide-title a
{
color : red;
}
我正在尝试覆盖锚标记的 CSS。这就是我的工作方式
<style>
@if (Model.Param.H1CSS!= null)
{
<text>
.slide-title a
{
@Html.RenderCSSAndJSAttributes(Model.Param.H1CSS).ToString().Replace("style=","")
}
</text>
}
</style>
方法 Html.RenderCSSAndJSAttributes
正在生成样式 color:#001595 !important;font-family:Book Antiqua !important;Text-align:10px;Text-align:Center
有没有更好的方法来覆盖 class CSS 或使用 jquery 附加内联 CSS?如有任何建议,我们将不胜感激。
提前致谢
更改自定义助手可能如下所示:
namespace System.Web.Mvc {
public static class HtmlHelperExtensions {
public static MvcHtmlString RenderLinkTracking(this HtmlHelper helper, string url, string linkText, string style) {
//...
return MvcHtmlString.Create(String.Format("<a href='{0}' style='{1}'>{2}</a>", url, style, linkText));
}
}
}
所以您可以像这样为每个自定义 link 传递样式:
<div class=".slide-title">
<H1>
@RenderLinkTracking(m => m.btn,Model.yourUrl, Model.bTnTitle, Model.Param.H1CSS)
</H1>
</div>
简单的解决方案是为锚点层次结构创建另一个 CSS 样式 .slide-title h1 a
.slide-title a
{
color:#001595!important;
}
.slide-title h1 a
{
color: green!important;
}
<div class="slide-title">
<h1>
<a href="/home/" data-id="Image Title<">H1 Anchor</a>
</h1>
<a href="/home/" data-id="Image Title<">Simple Anchor</a>
</div>
我有一个 H1 标签,里面有一个从代码生成的锚标签
<div class=".slide-title">
<H1>
@RenderLinkTracking(m => m.btn, Model.bTnTitle)
</H1>
</div>
RenderLinkTracking 创建锚标记
<a href="/home/" data-id="Image Title<">Image Title</a>
锚标签的CSS是
.slide-title a
{
color : red;
}
我正在尝试覆盖锚标记的 CSS。这就是我的工作方式
<style>
@if (Model.Param.H1CSS!= null)
{
<text>
.slide-title a
{
@Html.RenderCSSAndJSAttributes(Model.Param.H1CSS).ToString().Replace("style=","")
}
</text>
}
</style>
方法 Html.RenderCSSAndJSAttributes
正在生成样式 color:#001595 !important;font-family:Book Antiqua !important;Text-align:10px;Text-align:Center
有没有更好的方法来覆盖 class CSS 或使用 jquery 附加内联 CSS?如有任何建议,我们将不胜感激。
提前致谢
更改自定义助手可能如下所示:
namespace System.Web.Mvc {
public static class HtmlHelperExtensions {
public static MvcHtmlString RenderLinkTracking(this HtmlHelper helper, string url, string linkText, string style) {
//...
return MvcHtmlString.Create(String.Format("<a href='{0}' style='{1}'>{2}</a>", url, style, linkText));
}
}
}
所以您可以像这样为每个自定义 link 传递样式:
<div class=".slide-title">
<H1>
@RenderLinkTracking(m => m.btn,Model.yourUrl, Model.bTnTitle, Model.Param.H1CSS)
</H1>
</div>
简单的解决方案是为锚点层次结构创建另一个 CSS 样式 .slide-title h1 a
.slide-title a
{
color:#001595!important;
}
.slide-title h1 a
{
color: green!important;
}
<div class="slide-title">
<h1>
<a href="/home/" data-id="Image Title<">H1 Anchor</a>
</h1>
<a href="/home/" data-id="Image Title<">Simple Anchor</a>
</div>