【发布时间】:2011-05-11 20:18:04
【问题描述】:
在我的 HTML 中,我很好奇使用 <toys> 等唯一标识符而不是 <h1> 在语义上是否正确。例如:
我想拥有:
<toys class="grid_4 push_2"> </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"> </h1>
使用 CSS:
h1.push_2 {
background: url("toys.png") no-repeat scroll 0 0 transparent;
width: 181px;
height: 93px;
margin-top: -8px;
}
使用像<toys> 这样的唯一标识符在语义上是否正确?
【问题讨论】:
-
抛开关于维护的更大问题,如果它为您的目标受众正确呈现,它就是有效且语义正确的 html。
-
使用组件方法,是的(以 React 和 AngularJs 组件为例)。但是,我不建议将其用于一般用途(即,只是在没有概念支持的情况下将新标签扔在风中)
-
您的自定义标签(元素)不得命名为“toys”,而
以避免与未来标准命名冲突,您的自定义元素名称必须包含连字符(w3.org/TR/custom-elements/#custom-element-conformance);
标签: html css semantic-markup