<div class="form-group col-sm-5">
@Html.LabelFor(m => m.foo)
<a data-toggle="popover" data-content="I'm a popover!" href="#"> <span class="glyphicon glyphicon-info-sign"></span></a>
</div>
的<a>
元件(即glyphicon酥料餅)元素出現的label
元件的下方,但我想將它放置到標籤的右側代替。有沒有辦法通過在@Html.LabelFor
中嵌套<a>
來實現這一點?有這樣的事情會很酷:<a>嵌套內部Html.LabelFor
<label for="foo"> I'm the label!
<a data-toggle="popover" data-content="I'm a popover!" href="#"> <span class="glyphicon glyphicon-info-sign"></span></a>
</label>
如果沒有,我將不得不使用定位嗎?
編輯:我結束了服用拉莫的意見,並與一些簡單的滾動。
<div class="form-group col-sm-5">
<label>
<span> I'm a **hard-coded** LabelFor DataAnnotation! </span>
<a data-toggle="popover" data-content="I'm a popover!" href="#">
<span class="glyphicon glyphicon-info-sign"></span>
</a>
</label>
</div>
仍然有興趣,如果有一個MVC的方式來獲得Glyphicons與@Html.LabelFor
凝聚,但我的問題是或多或少的學術在這一點上。
編輯#2:我發現了一個更簡單的解決方案這是一種明顯的後見之明。該方法使用定位(即,display: inline
)以確保伴隨的<a>
和<span>
元件顯示在相同的線上。
<div class="col-sm-5 form-group">
@Html.LabelFor(m => m.foo, new { style = "display: inline;" })
<a data-toggle="popover" data-content="I'm a popover!" href="#"> <span class="glyphicon glyphicon-info-sign"></span></a>
</div>
這是更適合作爲評論不是答案。除了告訴人們再去google一些之外,你幾乎沒有提供任何有用的信息 – urnotsam 2014-10-27 19:11:35
Ramo的建議最有幫助,因爲在MVC中似乎沒有任何方法可以獲得我要查找的*特定*行爲。 – alex 2014-12-08 20:54:46