Apply CSS Style to Razor elements eg EditorFor

0

How do I apply a style to all EditorFor of my View ?

Example field :

@Html.EditorFor(model => model.Photo, new {htmlAttributes = new {@class = "form-control"}})

I tried to do this but did not:

<style>
    Html.EditorFor{
        width:500px;
    }
</style>

and also like this:

<style>
    EditorFor{
        width:500px;
    }
</style>
    
asked by anonymous 14.12.2016 / 23:31

1 answer

1

The EditorFor generates tags HTML and it is in them that we apply size , styles ( css ), etc. .

The table below looks at the EditorFor depending on the data type:

| --- Property DataType --- | ------ Html Element ------ |
| string                    |   <input type="text">      | 
| int                       |   <input type="number">    | 
| decimal, float            |   <input type="text">      | 
| boolean                   |   <input type="checkbox">  |
| Enum                      |   <input type="text">      |
| DateTime                  |   <input type="datetime">  |
| ------------------------------------------------------ |

Site table reference: tutorialsTeacher.com strong>

To assign CSS with standard size follow the examples below:

Place size in all input

input {
  width: 500px;
}
<input type="text" />

Put size in all% of type text ?

input[type="text"] {
  width: 500px;
}
<input type="text" />
<input type="password" />

Note: Only input of type input gets the default size of text

With these two examples you can create CSS for certain data types, or for a certain type of 500px HTML .

References:

15.12.2016 / 01:47