2009-11-24 24 views
0

我在我的MVC應用程序中有以下標記。我怎樣才能將課程應用於我的文本框?如何在MVC應用css類Html.TextBox

<%= Html.TextBox("username", "", new { maxlength = 50 })%> 
+2

你有什麼似乎是一個正確的答案 - 接受呢? – 2009-11-25 21:20:55

回答

10
<%= Html.TextBox("username", "", new { maxlength = 50, @class = 'your-classname' })%> 

然後在你的CSS文件,你可以使用這個選擇:

.your-classname { ...css rules here... } 
0

假設輸入框的類名是 「用戶名」,然後使用:

input[type=text].username { 
    /* styles here */ 
} 
0

根據您的代碼,我相信Html.TextBox幫助器方法也會自動從名稱字段中創建一個ID:

id="username" 

然後,您可以通過使用CSS訪問文本框:

#username { 
    /* styles */ 
} 
相關問題