5 回答

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超4個(gè)贊
我們可以使用它周圍的 div 并為 div 添加類,
<div class="style">
@Html.DisplayNameFor(model => model.title)
</div>
并為 .style 類編寫(xiě)樣式,我不知道這是否是正確的方法,但它對(duì)我有用。

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超2個(gè)贊
@Html.DisplayFor
不會(huì)工作,因?yàn)樗讳秩救魏?html 標(biāo)簽,而是渲染純文本。您可以在瀏覽器中按 F12 并檢查,您會(huì)發(fā)現(xiàn)沒(méi)有標(biāo)簽,只有原始內(nèi)容。
使用
@Html.LabelFor(model => model.Whatever, htmlAttributes: new { @class = "your css" })

TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超10個(gè)贊
這是一個(gè)舊線程,但這對(duì)我有用。希望這可以幫助現(xiàn)在搜索的人:@Html.LabelForModel(model.Whatever, new { @style = "color: red" })

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超21個(gè)贊
嘗試這個(gè)
@Html.Label("GP", item.GP, new { @style = "color:Red;" })

TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊
我有兩種方法可以做到這一點(diǎn):
1:給<label></label>類和風(fēng)格:
@Html.LabelFor(model => model.Title, new { @class = "myCssClass" })
2:使用您必須渲染內(nèi)容的代碼,但將其包裝在 div 中并定位其內(nèi)容:
<div class="myClass">
<h3>@Html.DisplayFor(model => model.Title)</h3>
@Html.DisplayFor(model => model.Title)
@Html.DisplayFor(model => model.Title)
@Html.DisplayFor(model => model.Title)
@Html.DisplayFor(model => model.Title)
@Html.DisplayFor(model => model.Title)
</div>
CSS:
div.myClass {
color: #00BFFF;
}
div.myClass h3{
color: Gold;
}
- 5 回答
- 0 關(guān)注
- 266 瀏覽
添加回答
舉報(bào)