2012-03-27 107 views
0

我想在我的视图中设置一个特定文本框的宽度。不管是什么我已经试过,在的site.css下面的代码优先:如何覆盖Html.TextBoxFor的输入[type =“text”]?

input[type="text"], input[type="password"] 
{ 
    // other properties 
    width: 200px; 
} 

我曾尝试:

@Html.TextBoxFor(model => model.Headline, new { style = "width: 400" }) 

@Html.TextBoxFor(model => model.Headline, new { @class = "wide" }) 

@Html.TextBoxFor(model => model.Headline, new { @id = "headline" }) 

但唯一重要的是输入[type =“text”]宽度。我不想改变全部的输入,只是这一个。

我没有在.wide和#headline的.css文件中设置宽度。

回答

0

为什么不使用输入[name =“name”]或一个例子的id?如果你想让一种风格比另一种风格更重要,那么在CSS属性结尾使用!重要。像:

input[type="text"] { 
    width: 200px; 
} 
input[name="foo"] { 
    width: 500px !important; 
} 

希望有帮助。

+0

感谢。你的建议,以及我之前尝试过的所有内容,都可以工作,如果我在CSS文件中默认的“输入”设置之后放*。 – 2012-03-27 22:05:29

0

围棋与

.wide { 
    width: 500px !important; 
} 
@Html.TextBoxFor(model => model.Headline, new { class = "wide" }) 

#wideBox { 
    width: 500px; 
} 
@Html.TextBoxFor(model => model.Headline, new { id = "wideBox" }) 
相关问题