Implementation of
CSS in HTML Helper in MVC
If we see
the all controls which we created using HTML Helper, they all are overloaded.
There is overload method in which we pass HtmlAttribute of type object. In this
object we pass the object in which we define the style of control.
For
example:-
@Html.Label("Enter your First name", new { style = "background-color:green;
color:white; font-family:Arial" })
Similarly we can pass the CSS style to each control.
If we want to pass CSS class to any Control then we can
use this code in following way:-
First create the CSS file. I added the CSS file name
TechAltum in which I added one CSS code for Label
.LableStyle { background-color:green; color:white; font-family:Arial
}
Now pass
this class code to the control
@Html.Label("Enter your First name", new { @class="LableStyle" })
Note:-kindly attach the CSS file in head tag using
following code:-
<link href="~/TechAltum.css" rel="stylesheet" />
Output of this code as follows:-
Figure 1
For any
query send mail at Malhotra.isha3388@gmail.com
Nice Post ,It really Help me ,Giving 5 star
ReplyDelete