使用自定义HTML属性并用CSS对其进行样式是不好的做法吗? [英] Is it a bad practice to use custom HTML attributes and style them with CSS?

查看:106
本文介绍了使用自定义HTML属性并用CSS对其进行样式是不好的做法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这样创建一个CSS类有没有什么问题:

Is there any problem creating a CSS class like this:

[test] {font:13px; }

[test] { font: 13px; }

并在HTML属性中使用,如下所示:

and use it in an HTML attribute as this:

< div test>< / div>

某些浏览器的性能会受到这种方法?

Would the performance in some browsers be affected by using this method?, I've tested it with Mozilla Firefox and Google Chrome and they seem to work with no problems.

推荐答案

您的自定义属性不是有效的HTML。如果要在元素上放置自定义数据,则必须使用 data - * 属性。

Your custom attributes are not valid HTML. You must use data-* attributes if you want to put custom data on your elements. This makes what you are doing bad practice.

此外,还有一些CSS类应该满足你的需要,除非你的问题比你所描述的更多。

In addition, there are CSS classes already that should meet your needs, unless there is more to your question than you have described.

这篇关于使用自定义HTML属性并用CSS对其进行样式是不好的做法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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