Solved

CSS Input Type Text Not Working?

Posted on 2013-11-11
7
522 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

760 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

17 Experts available now in Live!

Get 1:1 Help Now