我试图在文本后显示 asterisk red star
,但文本的宽度不允许在文本后插入星号。看下面的例子
代码
<div class="col-sm-4 col-sm-offset-1 required-field">
@Html.LabelFor(model => model.ContactPhoneNumber, new { @class = "control-label-nobold" })
</div>
生成HTML
<div class="col-sm-4 col-sm-offset-1 required-field">
<label class="control-label-nobold" for="ContactPhoneNumber">If you wish to be contacted by phone, enter your phone number</label>
</div>
CSS
.required-field:after {
content: "*";
font-weight: bold;
color: red;
}
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
页面
星标显示下一行
文本的宽度不允许我添加星号
如何在文本旁边添加星号?
最佳答案
将 :after 添加到标签。
.required-field .control-label-nobold:after {
content: "*";
font-weight: bold;
color: red;
}
更新:抱歉,错过了 .required-field 类。
关于jquery - 在文本后显示所需的星号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21242385/