Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML label color in ASP.NET MVC

I have a very general web page where I display information. I have this code in my .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.

like image 764
Tulips Avatar asked Jun 19 '12 14:06

Tulips


People also ask

How do you change the color of a label in HTML?

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.

What is HTML LabelFor?

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.

How does ValidationMessageFor work in MVC?

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.

How do you add a style to a label in HTML?

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.


2 Answers

I just did the following and it worked for me:

@Html.Label("This is a label", new { style = "color:#ff0000"})
like image 169
Bester Avatar answered Sep 20 '22 08:09

Bester


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

like image 32
Yusubov Avatar answered Sep 20 '22 08:09

Yusubov