我可以安全地使用unicode字符(例如口音)在CSS类名称或ids吗? [英] Can I safely use unicode characters (e.g. accents) in CSS class names or ids?

查看:133
本文介绍了我可以安全地使用unicode字符(例如口音)在CSS类名称或ids吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚遇到一种情况,产品名称会自动拉入我的HTML作为类名称,其中一个产品名称有重音符号。它看起来像这样:

I just encountered a situation where product names are automatically pulled in to my HTML as class names, and one of those product names has an accented letter. It looks like this:

<div class="español">Hola</div>

如果我添加一个CSS声明类,像这样:

If I add a CSS declaration with that class, like this:

.español {background:yellow;}

它会造成任何问题吗?它似乎工作到目前为止,但我不知道如果它是完全跨浏览器兼容。

Will it cause any problems? It seems to work so far, but I'm not sure if it's completely cross-browser compatible.

此外,如果是一个id而不是一个类,它会有什么不同吗?这似乎工作到目前为止,但是,我再也不知道是否会阻止到处。

Also, would it be any different if that were an id instead of a class? That seems to work so far, too, but again I am not sure if it'll hold up everywhere.

推荐答案

显然是。实际上,HTML 4.01已允许您在 <$ c $中使用Unicode字符c> class 属性。现在,HTML 5还允许他们在 id 属性。很酷的事情是,它已经测试与IE 6和工作,所以它向后兼容。

Apparently yes. In fact, HTML 4.01 already allowed you to use Unicode characters in the class attribute. Now HTML 5 allows them also on the id attribute. The cool thing is that it's been tested with IE 6 and works too, so it's backwards compatible.

现在你应该问自己是, / em>需要他们?在我的眼睛只是要求麻烦,因为虽然W3接受他们,一些不主要的浏览器可能不支持他们(为视障人士或其他人的浏览器)。

Now what you should ask yourself is, do I really need them? In my eyes is just asking for trouble because while the W3 accepts them, some not-major browser might not support them (think browsers for the visually impaired or others).

有关此主题的详情,请阅读此文章: http://mathiasbynens.be/notes/html5-id-class

Read this for more info on the subject: http://mathiasbynens.be/notes/html5-id-class.

这篇关于我可以安全地使用unicode字符(例如口音)在CSS类名称或ids吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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