带有 ID 属性的结束标签

发布于 2024-12-27 03:27:50 字数 346 浏览 5 评论 0原文

问题:如果我以这种方式关闭任何 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

这样的小城市 2025-01-03 03:27:50

不,这是无效的。

虽然它可能不会破坏您的代码,但它可能!

您应该只使用注释

;


经过检查,此

在验证器

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:

Elements may have associated properties, called attributes, which may
have values (by default, or set by authors or scripts).
Attribute/value pairs appear before the final ">" of an element's
start tag. Any number of (legal) attribute value pairs, separated by
spaces, may appear in an element's start tag.

http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2

凝望流年 2025-01-03 03:27:50

这里是如何关闭 div 的:

<div id="tagid" ></div>

如果你想识别标签的结束位置,你可以简单地添加注释:

<div id="tagid" >
   ...
</div><!-- Tagid Ends here -->

here how you close a div:

<div id="tagid" ></div>

if you want to recognize where the tag ends you can simply add a comment:

<div id="tagid" >
   ...
</div><!-- Tagid Ends here -->
只等公子 2025-01-03 03:27:50

引用我在 stackoverflow 中的其他答案:

最近必须对旧代码进行维护,我发现在 a 末尾使用注释由于 HTML 没有可嵌套的注释标签,div 标签确实使注释掉大段代码变得困难。因此,我养成了将注释修改为大块 div 末尾的隐藏跨度的习惯。

<div class="modal fade" id="dialog_edit_group">
    <div class="modal-dialog">
        <div class="modal-content">
            ...HTML content here...
        </div><span title=".modal-content" HIDDEN></span>
    </div><span title=".modal-dialog" HIDDEN></span>
</div><span title=".modal #dialog_edit_group" HIDDEN></span>
<!--
<div class="modal fade" id="dialog_edit_group_OLD">
    <div class="modal-dialog">
        <div class="modal-content">
            ...HTML content here...
        </div><span title=".modal-content" HIDDEN></span>
    </div><span title=".modal-dialog" HIDDEN></span>
</div><span title=".modal #dialog_edit_group_OLD" HIDDEN></span>
-->

我将“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.

<div class="modal fade" id="dialog_edit_group">
    <div class="modal-dialog">
        <div class="modal-content">
            ...HTML content here...
        </div><span title=".modal-content" HIDDEN></span>
    </div><span title=".modal-dialog" HIDDEN></span>
</div><span title=".modal #dialog_edit_group" HIDDEN></span>
<!--
<div class="modal fade" id="dialog_edit_group_OLD">
    <div class="modal-dialog">
        <div class="modal-content">
            ...HTML content here...
        </div><span title=".modal-content" HIDDEN></span>
    </div><span title=".modal-dialog" HIDDEN></span>
</div><span title=".modal #dialog_edit_group_OLD" HIDDEN></span>
-->

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.

葬花如无物 2025-01-03 03:27:50

在 HTML/XML 中,属性只能放置在元素的开始标记中。您正在生成无效的 html。

In HTML/XML attributes may only be placed in the start tag of an element. You're producing invalid html.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文