我在MVC视图页面中有这个控件
@Html.TextBoxFor(m => m.TemplateGroupName,
new { tabindex = "1", placeholder = "Enter Template Group Name" })
生成的控制标记: -
<input class="input-validation-error" data-val="true"
data-val-required="The TemplateGroupName field is required."
id="TemplateGroupName" name="TemplateGroupName"
placeholder="Enter Template Group Name"
tabindex="1" value="" type="text">
我正在尝试将占位符文本居中对齐。 请建议。
答案 0 :(得分:3)
将以下css放在您的页面上。它将在所有浏览器中居中对齐占位符:
::-webkit-input-placeholder {
text-align: center;
}
:-moz-placeholder { /* Firefox 18- */
text-align: center;
}
::-moz-placeholder { /* Firefox 19+ */
text-align: center;
}
:-ms-input-placeholder {
text-align: center;
}
OR
您可以将样式实现到特定的文本框,如下所示:
@Html.TextBoxFor(m => m.TemplateGroupName,
new { tabindex = "1", placeholder = "Enter Template Group Name", Style = "text-align:center;" })
答案 1 :(得分:0)
为了在MVC中对齐文本框中的内容,我们使用“Text-Align”属性。
@Html.TextBox("Name",new{placeholder="Your Text",style="Text-align:Center"});