I have a very general web page where I display information. I have this code in my .cshtml:
<div style="text-align: left">
Test <p style="color: #1e83ca;"> @Html.Label(Model.MemberName) </p>
Beruf @Html.Label(Model.ProfessionName)
Datum @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.
To set the font color in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property color. HTML5 do not support the <font> tag, so the CSS style is used to add font color.
LabelFor() The Html. LabelFor<TModel,TProperty>() helper method is a strongly typed extension method. It generates a html label element for the model object property specified using a lambda expression. Visit MSDN to know all the overloads of LabelFor() method.
ASP.NET MVC: ValidationMessageFor ValidationMessageFor() is a strongly typed extension method. It displays a validation message if an error exists for the specified field in the ModelStateDictionary object. Visit MSDN to know all the overloads of ValidationMessageFor() method.
A style contains any number of CSS property/value pairs, separated by semicolons (;). The style attribute overrides any other style that was defined in a <style> tag or an external CSS file. This inline styling affects the current <label> element only.
I just did the following and it worked for me:
@Html.Label("This is a label", new { style = "color:#ff0000"})
As mentioned in my comments, try to use <span>
. That will work !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With