使用自定义HTML代码 [英] Using custom HTML Tags

查看:259
本文介绍了使用自定义HTML代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的html中,我很好奇,如果使用独特的标识符,如< toys> < / toys> code>保存图像而不是< h2> 。例如:

In my html I was curious if it was semantically correct to use unique identifiers such as <toys> </toys> to hold an image rather than an <h2>. For example:

优先选择:
< toys class =grid_4 push_2>& nbsp< toys>

使用css:

    toys {
    background: url("toys.png") no-repeat scroll 0 0 transparent;
    width: 181px;
    height: 93px;
    margin-top: -8px;
    }

而不是:我目前有:
< h1 class =grid_4 push_2>& nbsp< / h1>

b
$ b

with the css:

    h1 {
    background: url("toys.png") no-repeat scroll 0 0 transparent;
    width: 181px;
    height: 93px;
    margin-top: -8px;
    }

是使用唯一标识符< toys> ; 语义正确?

Is the use of unique identifiers like <toys> semantically correct?

推荐答案

最好避免使用自定义标签,因为你永远不知道什么时候这些标签可能会变得标准化,并且在将来有特殊用途。

It is best to avoid using custom tags, as you never know when those tags may become standardized, and have special usage in the future.

对于您的示例,最好的做法是,如果您想避免使用标头标签,

The best thing to do for your example, if you want to avoid using the header tags, is the following:

<div class="toys grid_4 push_2">&nbsp</div>

.toys {
    background: url("toys.png") no-repeat scroll 0 0 transparent;
    width: 181px;
    height: 93px;
    margin-top: -8px;
}

此外

如果在设计页面时不使用标准html标签,当样式被禁用时,它们不会以任何有组织的方式显示。这不是一个问题,但是,如果因为任何原因,你需要查看玩具没有样式的列表,你是运气不好,除非你使用< ul> < ol> < li> 标签。

If you do not use standard html tags when designing pages, they will not appear in any organized manner when styles are disabled. This is not a problem, going forward, but if for any reason you needed to view a list of "toys" without styles, you had be out of luck unless you use <ul> or <ol> with <li> tags.

更新:

UPDATE:

Flimzy在评论中指出,自己的W3C规范。

As Flimzy pointed out in the comments, custom HTML elements now have their own W3C specification. However, they are not yet fully supported.

  • Specification: https://www.w3.org/TR/custom-elements/
  • Support: http://caniuse.com/#feat=custom-elements

这篇关于使用自定义HTML代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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