带有 ID 属性的结束标签
问题:如果我以这种方式关闭任何 html 标签(包括 id 属性):
<div id="tagid" >...more html
...
</div id="tagid" >
它会影响页面,或者不喜欢它,或者破坏任何 W3C 规则...我该怎么办它……会以任何方式影响吗?
为什么?:纯粹是个人喜好。
我没有在标签旁边写额外的注释,而是简单地添加 id 来帮助我知道什么标签被关闭 - 标签以任何方式关闭,所以我想它不会做任何事情(或者我认为)
PS。仅供参考,我是初学者
Question: If I close any html tag in this fashion (Including the id property):
<div id="tagid" >...more html
...
</div id="tagid" >
Will it affect the page, or won't like it, or disrupt any W3C rules...how can I put it...will it affect in any way?
Why?: Simply personal preference.
Instead of writing additional comments next to the tag, I simply add the id to help me know WHAT tag is closed -The tag is closed any way, so I guess it won't do anything (or so I think)
PS. FYI, I am a beginner
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不,这是无效的。
虽然它可能不会破坏您的代码,但它可能!
您应该只使用注释
;
经过检查,此
在验证器
http://validator.w3.org/#validate_by_input
虽然没有特别提到非法,但 HTML 规范仅提到出现在开始标记中的
属性
:http://www.w3.org/TR/html4 /intro/sgmltut.html#h-3.2.2
No this is not valid.
While it might not break your code, it could!
You should just use the comments
</div> <!-- closing main content div -->
After checking, this
<div></div id="tagid" >
breaks in the validator
http://validator.w3.org/#validate_by_input
Although not specifically mentioned as illegal, the HTML spec only mentions
attributes
as appearing within the start tag:http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2
这里是如何关闭 div 的:
如果你想识别标签的结束位置,你可以简单地添加注释:
here how you close a div:
if you want to recognize where the tag ends you can simply add a comment:
引用我在 stackoverflow 中的其他答案:
最近必须对旧代码进行维护,我发现在 a 末尾使用注释由于 HTML 没有可嵌套的注释标签,div 标签确实使注释掉大段代码变得困难。因此,我养成了将注释修改为大块 div 末尾的隐藏跨度的习惯。
我将“HIDDEN”HTML5 属性放在那里,这样如果其他人出于某种原因修改它并添加文本,内容通常会保持隐藏状态。我把它全部大写,这样它会更突出一点,就好像在喊“在这里评论!”。是的,它确实创建了一个 DOM 元素,现在必须由浏览器维护,但在繁重的活跃网站开发过程中,这是一个很小的代价。
使用“end div comments”本身符合 HTML 标准,为我提供了更大的可读性,并允许我使用 HTML 注释标签来禁用页面的大块以帮助开发。也许对其他人也有用。
Quoting my other answer in stackoverflow:
Recently having to perform maintenance on older code, I found that using comments at the end of a div tag really made it difficult to comment out large sections of code thanks to HTML not having nestable comment tags. So, I got into the habit of modifying the comments into hidden spans at the end of large block divs.
I put the "HIDDEN" HTML5 attribute in there so if others modify it and add text for some reason, the contents will usually stay hidden. I made it ALL CAPS so that it would stand out a bit more as if to shout "COMMENT HERE!". Yes, it does create a DOM element that now has to be maintained by the browser, but its a small price to pay during heavy active website development.
Using "end div comments" as such conforms to the HTML standard, gives me greater readability and allows me to use the HTML comment tag to disable large blocks of the page to aid in development. Maybe it will be useful for others as well.
在 HTML/XML 中,属性只能放置在元素的开始标记中。您正在生成无效的 html。
In HTML/XML attributes may only be placed in the start tag of an element. You're producing invalid html.