在 HTML 中显示街道地址最语义化的方式是什么?

发布于 2024-08-23 01:11:00 字数 256 浏览 8 评论 0原文

我有一个将在网页上显示的地址,但它不是该页面作者的地址。根据 w3c 建议<,应如何将其编码为语义< /a> 的:

作者可以使用 ADDRESS 元素来提供文档或文档主要部分(例如表单)的联系信息。该元素通常出现在文档的开头或结尾。

I have an address that is going to be displayed on a webpage, but it is not the address for the author of the page. How should this be coded to be semantic given the w3c recommendation of:

The ADDRESS element may be used by authors to supply contact information for a document or a major part of a document such as a form. This element often appears at the beginning or end of a document.

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

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

发布评论

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

评论(4

说谎友 2024-08-30 01:11:00

您可以使用 hCard 微格式 来描述您的地址。微格式的优点是您可以在现有文档中使用它们来丰富它们。

下面是一个源自 Microformats wiki 的示例:

<address class="vcard">
  <span class="adr">
    <span class="street-address">169 University Avenue</span>
    <span class="locality">Palo Alto</span>,  
    <abbr class="region" title="California">CA</abbr>  
    <span class="postal-code">94301</span>
    <span class="country-name">USA</span>
  </span>
</address>

You could use the hCard Microformat to describe your address. The advantage of Microformats is that you can use them in your existing documents to enrich them.

Here’s an example derived from the example from the Microformats wiki:

<address class="vcard">
  <span class="adr">
    <span class="street-address">169 University Avenue</span>
    <span class="locality">Palo Alto</span>,  
    <abbr class="region" title="California">CA</abbr>  
    <span class="postal-code">94301</span>
    <span class="country-name">USA</span>
  </span>
</address>
绝情姑娘 2024-08-30 01:11:00

Gumbo 的答案缺少一种成分。 hcard/vcard需要有名称 (fn)。

http://microformats.org/wiki/hcard#Property_List

另外,地址标签不应该是在这种情况下使用它是因为它专门用于与其显示的页面的作者相关。

<div class="vcard">
  <span class="fn">Tristan Ginger</span>
  <span class="adr">
    <span class="street-address">169 University Avenue</span>
    <span class="locality">Palo Alto</span>,  
    <abbr class="region" title="California">CA</abbr>
    <span class="postal-code">94301</span>
    <span class="country-name">USA</span>
  </span>
</div>

大多数想要在其网站上显示其地址的企业应使用以下内容:

<address class="vcard">
  <span class="fn org">Tristan Ginger Inc</span>
  <span class="adr">
    <span class="street-address">69 University Avenue</span>
    <span class="locality">Great Bookham</span>,  
    <span class="region">Surrey</span>
    <span class="postal-code">KT22 9TQ</span>
    <span class="country-name">UK</span>
  </span>
</address>

The answer by Gumbo is missing an ingredient. An hcard/vcard is required to have a name (fn).

http://microformats.org/wiki/hcard#Property_List

Also the address tag should not be used in this case as it is specifically used to relate to the author of the page it is displayed on.

<div class="vcard">
  <span class="fn">Tristan Ginger</span>
  <span class="adr">
    <span class="street-address">169 University Avenue</span>
    <span class="locality">Palo Alto</span>,  
    <abbr class="region" title="California">CA</abbr>
    <span class="postal-code">94301</span>
    <span class="country-name">USA</span>
  </span>
</div>

Most business wanting to display their address on their website should use the following:

<address class="vcard">
  <span class="fn org">Tristan Ginger Inc</span>
  <span class="adr">
    <span class="street-address">69 University Avenue</span>
    <span class="locality">Great Bookham</span>,  
    <span class="region">Surrey</span>
    <span class="postal-code">KT22 9TQ</span>
    <span class="country-name">UK</span>
  </span>
</address>
弥枳 2024-08-30 01:11:00

您可以使用 RDFa,例如:

<html
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:foaf="http://xmlns.com/foaf/0.1/"
    xmlns:address="http://schemas.talis.com/2005/address/schema#"
    xml:lang="fr" lang="fr"
>
 <head>...</head>
 <body>
  <div typeof="foaf:Person" about="http://you.openid.com#me">
   <span id="name" property="foaf:name">First Name, Last Name</span>
   <address property="address:streetAddress">My Street, My City</address>
  </div>
 </body>
</html>

you can use RDFa, eg:

<html
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:foaf="http://xmlns.com/foaf/0.1/"
    xmlns:address="http://schemas.talis.com/2005/address/schema#"
    xml:lang="fr" lang="fr"
>
 <head>...</head>
 <body>
  <div typeof="foaf:Person" about="http://you.openid.com#me">
   <span id="name" property="foaf:name">First Name, Last Name</span>
   <address property="address:streetAddress">My Street, My City</address>
  </div>
 </body>
</html>
伏妖词 2024-08-30 01:11:00

为此,您可以使用 Schema.org 词汇表的 PostalAddress 项。它可以通过微数据RDFa,或 JSON- LD。

例如,使用 RDFa:

<div vocab="http://schema.org/" typeof="PostalAddress">
 <span property="name">Google Inc.</span>
 P.O. Box<span property="postOfficeBoxNumber">1234</span>
 <span property="addressLocality">Mountain View</span>,
 <span property="addressRegion">CA</span>
 <span property="postalCode">94043</span>
 <span property="addressCountry">United States</span>
</div>

AFAIK,这对于

代替封闭的

也应该有效:
<address vocab="http://schema.org/" typeof="PostalAddress">
 <span property="name">Google Inc.</span>
 P.O. Box<span property="postOfficeBoxNumber">1234</span>
 <span property="addressLocality">Mountain View</span>,
 <span property="addressRegion">CA</span>
 <span property="postalCode">94043</span>
 <span property="addressCountry">United States</span>
</address>

You can use the Schema.org vocabulary's PostalAddress item for this. It can be used via Microdata, RDFa, or JSON-LD.

For example, using RDFa:

<div vocab="http://schema.org/" typeof="PostalAddress">
 <span property="name">Google Inc.</span>
 P.O. Box<span property="postOfficeBoxNumber">1234</span>
 <span property="addressLocality">Mountain View</span>,
 <span property="addressRegion">CA</span>
 <span property="postalCode">94043</span>
 <span property="addressCountry">United States</span>
</div>

AFAIK, this should also be valid with <address> in place of the enclosing <div>:

<address vocab="http://schema.org/" typeof="PostalAddress">
 <span property="name">Google Inc.</span>
 P.O. Box<span property="postOfficeBoxNumber">1234</span>
 <span property="addressLocality">Mountain View</span>,
 <span property="addressRegion">CA</span>
 <span property="postalCode">94043</span>
 <span property="addressCountry">United States</span>
</address>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文