依靠 :after 向标签添加冒号是否安全?
我想向所有 label
元素添加冒号
form label:after {
content: " : ";
}
有什么理由不这样做?
I want to add colons to all my label
elements
form label:after {
content: " : ";
}
Any reason not to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对于
radio
和checkbox
输入,最佳做法是在输入后添加标签。In the case of
radio
andcheckbox
inputs it's best practice to add the label after the input.也许您应该只使用编辑器的查找/替换功能,而不是使用一些非跨浏览器的 CSS。
搜索
并替换为
:
如果您坚持在运行时执行此操作,则如前所述,使用 CSS 和IE 的预期风险。
或者使用某种 jQuery,例如
$(' : ').appendTo('label')
。Rather than using some non-cross-browser CSS, maybe you should just use your editor's find/replace function.
Search for
</label>
and replace with
: </label>
If you insist on doing this at runtime, then as previously mentioned, use either CSS with risks expected of IE.
or use some kind of jQuery, like
$('<span> : </span>').appendTo('label')
.较旧的浏览器(例如 IE 6)不支持此功能。设计人员避免使用此功能,因为它不跨浏览器兼容。除非您确定所有用户都将使用兼容的浏览器,否则您可能希望避免这种情况。
Older browsers (e.g. IE 6) do not support this. Designers avoid using this feature because it is not cross-browser compatible. Unless you are sure all your users will be using a compatible browser, you might want to avoid that.
许多旧浏览器不支持它。请参阅此处的兼容性图表:http://reference.sitepoint.com/css/pseudoelement-after
It's unsupported in many older browsers. See the compatibility charts here: http://reference.sitepoint.com/css/pseudoelement-after
这是一个品味问题。
从结构上来说,冒号可能没有理由出现在你的 html 中。这更多的是一种风格。所以它属于你的CSS。
问题是,在 IE7 上看到冒号对您来说有多重要。就我个人而言,我不会太在意。 IE7的使用率正在迅速下降(可能是因为win7自带了IE8),缺少冒号不会损害网站的人体工程学。所以我会考虑这种优雅的降级。
It's a matter of taste.
Structurally, the colon probably has no reason to be in your html. It's more of a style thing. So it belongs on your css.
Question becomes, how important is it for you to see the colon on IE7. Personally I wouldn't care too much. IE7 usage is going down quickly (probably because win7 comes with IE8) and missing a colon will not hurt the ergonomics of the website. So I would consider this graceful degradation.