Solved

CSS Input Type Text Not Working?

Posted on 2013-11-11
7
523 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now