记录 div 部分,使用 title 属性?

发布于 2024-12-05 04:00:18 字数 246 浏览 0 评论 0原文

我正在寻找最简洁的方式来记录页面的各个部分,例如 div 部分。

使用 title 属性有什么问题吗,例如

<div title="Payment Area" class="form">
   ...
</div>

PS 在相关的情况下,我正在使用 IntelliJ IDE,但对其各种功能不熟悉,例如自动格式控制和其他能够轻松理解页面部分的方法。

I'm looking for the most terse way to document sections of my page, e.g. div sections.

Anything wrong with using the title attribute, e.g.

<div title="Payment Area" class="form">
   ...
</div>

?

P.S. In case relevant, I'm using the IntelliJ IDE, but new to its various capabilities, e.g. automatic formatting control and other ways to be able to easily understand sections of my pages.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

記憶穿過時間隧道 2024-12-12 04:00:18

如果某个元素具有 title 属性,则当您将鼠标悬停在该元素上时,大多数浏览器都会显示带有该属性值的工具提示。在这种情况下,当您将鼠标悬停在该 div 上的任意位置时,它们会显示“付款区域”工具提示。

一般来说,HTML 属性都有其用途。 HTML 有文档注释!尝试一下:

<div class="form"> <!-- Payment Area -->
    ...
</div>

您提到您不想要评论的开销。如果你计算一下字符(包括属性之前所需的空格),它们实际上是相同的长度:(

 title="Payment Area"
<!-- Payment Area -->

但是,我同意,它们看起来确实更大!)

If an element has a title attribute, most browsers show a tooltip with the attribute’s value when you hover over it. In this case, they’ll show a “Payment Area” tooltip when you hover anywhere over that div.

HTML attributes, in general, have a purpose. HTML has comments for documentation! Try them:

<div class="form"> <!-- Payment Area -->
    ...
</div>

You mentioned that you didn't want the overhead of comments. If you count up the characters (including the required space before the attribute, they're actually the same length:

 title="Payment Area"
<!-- Payment Area -->

(But, I agree, they do look bigger!)

变身佩奇 2024-12-12 04:00:18

我可能会使用 id,这样您也可以将它们用作 CSS 和 JavaScript 的挂钩。

否则,Gabe's Answerdata 属性提供了一个很好的案例。 John Resig 在这里解释了为什么它们很好:http://ejohn.org/blog/ html-5-数据属性/

I would probably use ids, that way you can also use them as hooks for your CSS and JavaScript.

Otherwise, Gabe's Answer makes a good case for data attributes. John Resig explains why they are good here: http://ejohn.org/blog/html-5-data-attributes/

天煞孤星 2024-12-12 04:00:18

我建议使用 HTML5 自定义属性标准:

<div data-title='Payment Area'></div>

基本上,在名称前面加上 data- ,浏览器将忽略它。

I would recommend using the HTML5 custom attributes standard:

<div data-title='Payment Area'></div>

Basically, precede the name with data- and the browser will ignore it.

殊姿 2024-12-12 04:00:18

title 属性不适用于 div - 我还没有检查官方规范,但我认为它甚至不是受支持的属性。更好的做法是使用“id”属性。这样做的另一个好处是为 CSS 提供钩子。

您还可以更进一步,使用 html5,它为您提供更多描述性元素,例如


编辑:根据 steveax 的评论,标题属性无效。不过,我认为我的回答的要点仍然有效。

The title attribute isn't meant for divs - I haven't checked the official specs, but I don't think it's even a supported attribute. The better practice is to use the "id" attribute. This has the added benefit of providing hooks for your CSS.

You can also take it a step further and use html5, which provides you with more descriptive elements such as <nav>, <section>, <article> and <header>


Edit: as per comment by steveax, the title attribute isn't invalid. I think the gist of my answer remains valid, though.

破晓 2024-12-12 04:00:18

您可以使用 rel="" 属性,这对我来说效果很好,我认为标题不适用于 div

<div rel="Payment Area"></div>

You can use the rel="" attribute, that works pretty well for me, I don't think title works on divs

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