与结肠癌后缀标签文本 [英] Postfix label text with colon

查看:108
本文介绍了与结肠癌后缀标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用ASP.NET MVC 3,对于我的形式,我对准标签的文本的权利。此外,还有在标签和输入场之间的结肠。

I use ASP.NET MVC 3. For my forms, I align the label's text to the right. Also, there is a colon between the label and the input field.

Firstname: [          ]
     Last: [          ]

我使用CSS或MVC 3一些C#code自动插入这个冒号?

我想出了迄今为止最好的办法是使用 [显示(名称=名字:)] 属性,但是这个也有副作用包括本结肠验证消息:

The best thing I came up with so far is to use the [Display(Name="Firstname:")] attribute, but this has the side effect of also including this colon in validation messages:

[Required]
[Display(Name = "Firstname:")]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} character long.", MinimumLength = 1)]
public string Firstname { get; set; }

另一种方法是使用 LabelFor()方法重载,但是这迫使我指定两次(在模型CSHTML文件一次和一次)标签文本

The other alternative was to use the LabelFor() method overload, but this forces me to specify the label text twice (once in the Model and once in cshtml file):

<div>
    <div class="editor-label">@Html.LabelFor(x => x.Firstname, "Firstname:")</div>
    <div class="editor-field">@Html.TextBoxFor(x => x.Firstname)</div>
</div>

什么更好的建议?

Any better suggestions?

推荐答案

通过CSS,你可以伪类之后添加通过结肠。您可以找到有关这个伪类 href=\"http://www.quirksmode.org/css/beforeafter.html\">更多信息。

Through CSS, you can add the colon via the after pseudo class. You can find more information about this pseudo class here.

.editor-label > label:after {
    content: ": "
}

工作例如

http://jsfiddle.net/fJQDZ/

请注意,伪类无法在IE7。

Please note that the after pseudo class is not available in IE7.

这篇关于与结肠癌后缀标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆