2012-03-27 105 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" }) 
相關問題