【发布时间】:2014-12-23 00:54:42
【问题描述】:
<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> 元素(即字形弹出框)出现在 label 元素的下方,但我希望将其放在 右侧而是标签。有没有办法通过将<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>
如果不是,我是否必须使用定位来代替?
编辑:我最终接受了 Ramo 的建议,并采用了一些简单的方法。
<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>
【问题讨论】:
标签: html css asp.net-mvc twitter-bootstrap