ASP.NET MVC 中的 HTML 标签颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11103288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:08:45  来源:igfitidea点击:

HTML label color in ASP.NET MVC

htmlasp.net-mvc

提问by Tulips

I have a very general web page where I display information. I have this code in my .cshtml:

我有一个非常通用的网页,用于显示信息。我的 .cshtml 中有此代码:

<div style="text-align: left">
    Test&nbsp;&nbsp;<p style="color: #1e83ca;"> @Html.Label(Model.MemberName) &nbsp;&nbsp;&nbsp;&nbsp;</p>
    Beruf&nbsp;&nbsp;@Html.Label(Model.ProfessionName)&nbsp;&nbsp;&nbsp;&nbsp;
    Datum&nbsp;&nbsp;@Html.Label(Model.TestTakenDate.ToString()) 
</div>

I want differentiate the text that I display reading from the database from what is the fixed text. I am using the helper Label and there is no difference. I get all black text. How do I make only what is in the @Html.label in different color? OR what else can I use to make them look different.

我想区分我从数据库中读取的文本和固定文本。我正在使用助手标签,没有区别。我得到全黑文本。如何只制作不同颜色的@Html.label 中的内容?或者我还能用什么来让它们看起来不同。

采纳答案by Yusubov

As mentioned in my comments, try to use <span>. That will work !

正如我在评论中提到的,尝试使用<span>. 那可行 !

回答by Bester

I just did the following and it worked for me:

我只是做了以下工作,它对我有用:

@Html.Label("This is a label", new { style = "color:#ff0000"})

回答by VJAI

@Html.Label(Model.ProfessionName, new {@class = "mylabel" })

in css

在 CSS 中

.mylabel
{
   color: green;
}

回答by Greg B

Try giving your @Html.Label classes.

尝试提供您的 @Html.Label 类。

so in your css :

所以在你的 css 中:

.database { color: #1e83ca; }

and in your cshtml

并在您的 cshtml 中

@Html.Label(Model.MemberName, new { @class = "database"} )

回答by Robert Iver

Can you specify the HTML attributes by supplying an additional parameter to the Label HTMLHelper?

您能否通过向 Label HTMLHelper 提供附加参数来指定 HTML 属性?

Something like:

就像是:

<%= Html.Label("This is a label", new { style : "color:#FF0000;" } ) %>