Solved

CSS Input Type Text Not Working?

Posted on 2013-11-11
7
528 Views
Last Modified: 2013-11-16
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
Comment
Question by:WorknHardr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39639404
What is the rendered HTML?
0
 

Author Comment

by:WorknHardr
ID: 39640008
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
 
LVL 58

Accepted Solution

by:
Gary earned 400 total points
ID: 39640030
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
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!

 

Author Comment

by:WorknHardr
ID: 39640478
The width never changes if change the entire CSS to this:

[CSS]
 input[type=text].amount
    {
        width: 75px;
    }
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39641836
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
 
LVL 58

Expert Comment

by:Gary
ID: 39641897
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
 

Author Closing Comment

by:WorknHardr
ID: 39653136
Thx
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question