Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 546
  • Last Modified:

CSS Input Type Text Not Working?

I want to have a general css for all Html.EditorFor and Html.TextboxFor then specialize size when needed like so:

Problem: The width never changes to 75px

[HTML]
<td>@Html.EditorFor(x => x.Limit, new { @class="amount"})</td>

[CSS]
input[type=text]
    {
        border: 1px solid darkslategray;
        border-radius: 5px;
        -moz-border-radius: 5px;
        -webkit-border-radius: 5px;
        width: 150px;
        height: auto;
        color: darkslategray;
        font: normal 100% Arial;
    }

 input[type=text].amount
    {
        width: 75px;
    }
0
WorknHardr
Asked:
WorknHardr
  • 3
  • 3
1 Solution
 
GaryCommented:
What is the rendered HTML?
0
 
WorknHardrAuthor Commented:
Note: The 'Html.EditorFor' is in a MVC4 EditorTemplate (if that makes any difference)...

[View Source]
<input class="text-box single-line" data-val="true" data-val-number="The field Limit must be a number." data-val-required="The Limit field is required." id="Budgets_0__Limit" name="Budgets[0].Limit" type="text" value="9.00" /></td>
0
 
GaryCommented:
Ahh you cannot override the defaults.
You could pass in the style directly e.g.
new { style = "width: 75px" }

Or if it is worth it
http://aspadvice.com/blogs/kiran/archive/2009/11/29/Adding-html-attributes-support-for-Templates-_2D00_-ASP.Net-MVC-2.0-Beta_2D00_1.aspx
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
WorknHardrAuthor Commented:
The width never changes if change the entire CSS to this:

[CSS]
 input[type=text].amount
    {
        width: 75px;
    }
0
 
COBOLdinosaurCommented:
try it as
   input.amount[type=text] {width:75px !important;}

But I think Gary may be right and you can't override the default even with an important hack.

Cd&
0
 
GaryCommented:
You cannot pass in a custom class that way, it has its own classes that take precedence, and any new class you pass in will be ignored.
Either pass in the style directly (no class)
Or use the link I pointed to to make amendments in the objects.
0
 
WorknHardrAuthor Commented:
Thx
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now