Apply CSS Style to Razor elements ex: Editorfor

Asked

Viewed 749 times

0

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

Field example:

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

I tried to do it this way but I couldn’t:

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

and also so:

<style>
    EditorFor{
        width:500px;
    }
</style>
  • @Virgilio this works with elements with tags like 'div, a, p' and etc but in my case not... because there is used the Razor

  • so it is related, independent of anything input, div etc are tags html, and get into it. The problem is knowing what that line will generate? you could put that because the EditorFor generates from a type and the types of a class can and should vary. What input it generates?

  • Do you tell me to trade Editorfor for Input? No <Style>?

  • In vdd this size is just for testing to see if it works

  • you take a look at the answer?

Show 1 more comment

1 answer

1

The Editorfor generates tags HTML and are where we apply size, color, styles (css), etc..

The table below is how the Editorfor depending on the type of data:

| --- 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">  |
| ------------------------------------------------------ |

Reference of the site table: tutorialsTeacher.com


To assign CSS with standard size follow the examples below:

Put size in all input

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

Put size in all input of the kind text?

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

Observing: only the input of the kind text receives the standard size of 500px

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

References:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.