简体   繁体   English

HTML:从语义上标记地址?

[英]HTML: semantically mark up an address?

How do I mark up an address (eg a listing of businesses and their addresses)? 如何标记地址(例如,商家及其地址列表)? The problem is that I won't always have enough address information to complete a vCard microformat. 问题是我将永远不会有足够的地址信息来完成vCard微格式。 The address HTML tag is supposed to be contact information for the author of the page, so probably not the correct tag to use. address HTML标签应该是页面作者的联系信息,因此可能不是正确的标签。

Suggestions? 有什么建议吗?

Not entirely sure on what exactly your asking, but if it's from a search engine point of view your worried about give Schema.org a go. 不能完全确定您到底要问什么,但是如果是从搜索引擎的角度来看,您担心可以尝试一下Schema.org。 There is some great info and example on the local business page to help you markup the address for search engines. 本地商户页面上有一些不错的信息和示例,可以帮助您标记搜索引擎的地址。

There is currently no designated element for marking up a physical address or postal address. 当前没有用于标记物理地址或邮政地址的指定元素。 You are correct: <address> should be used only to represent contact information for the article or document author, so you should not use it to mark up the addresses in a listing of businesses for example. 您是正确的: <address>仅应用于表示文章或文档作者的联系信息,因此,例如,您不应使用它来标记企业列表中的地址。

When HTML doesn't exist for certain semantics, your best bet is to mark up the element closest in meaning, and then use auxiliary standards such as (1) Microformat classes, (2) Microdata attributes, and/or (3) ARIA roles. 当某些语义不存在HTML时,最好的选择是标记含义最接近的元素,然后使用辅助标准,例如(1)微格式类,(2)微数据属性和/或(3)ARIA角色。 Personally I prefer Microdata over Microformats because Microdata doesn't interfere with the [class] attribute, which is meant for styling. 我个人更喜欢微数据而不是微格式,因为微数据不会干扰[class]属性(该属性用于样式)。 I don't like to mix semantics with style. 我不喜欢将语义与样式混合在一起。 ARIA roles are for accessibility and I don't know enough about them to say much, but they are very good to have in your code. ARIA角色是为了实现可访问性,我对它们的了解还不够多,但是在您的代码中拥有它们非常好。

Read up on the Microdata syntax (an extension to HTML). 阅读Microdata语法 (HTML的扩展)。 Microdata is the official syntax in markup, whereas Schema.org is a very popular (Google loves it) vocabulary to use with the syntax. 微数据是标记中的官方语法 ,而Schema.org是该语法非常流行(谷歌喜欢它)的词汇 There are other less-popular vocabularies as well. 还有其他不受欢迎的词汇。

To mark up a physical address, use the Schema.org PostalAddress itemtype, with its corresponding properties. 要标记物理地址,请使用Schema.org PostalAddress项目类型及其相应的属性。 Honestly the best element to use would be a plain old <p> . 老实说,最好使用的元素是普通的<p>

<p itemscope itemtype="http://schema.org/PostalAddress">
  <span itemprop="name">The White House</span>
  <br/>
  <span itemprop="streetAddress">1600 Pennsylvania Avenue</span>
  <br/>
  <span itemprop="addressLocality">Washington</span>,
  <span itemprop="addressRegion">DC</span>
  <span itemprop="postalCode">20500</span>
  <br/>
  <data itemprop="addressCountry" value="US">United States of America</data>
  <br/>
  <span itemprop="url">https://www.whitehouse.gov/</span>
</p>

The <br/> element is meant to provide (semantic, meaningful) line breaks in content, so its use is justified here in a postal address. <br/>元素旨在提供(语义,有意义的)内容换行符,因此在邮政地址中使用此元素是合理的。 It's also an extremely conventional use case. 这也是一个非常常规的用例。 However it can be argued that a <pre> works just as well, as it is technically preformatted text. 但是,可以说<pre>也一样有效,因为它是技术上预先格式化的文本。

<pre itemscope itemtype="http://schema.org/PostalAddress">
  <span itemprop="name">The White House</span>
  <span itemprop="streetAddress">1600 Pennsylvania Avenue</span>
  <span itemprop="addressLocality">Washington</span>, <span itemprop="addressRegion">DC</span> <span itemprop="postalCode">20500</span>
  <data itemprop="addressCountry" value="US">United States of America</data>
  <span itemprop="url">https://www.whitehouse.gov/</span>
</pre>

Well, if it's a list of businesses and their addresses, perhaps you should use a list. 那么,如果它的企业和他们的地址的列表 ,也许你应该使用列表。 There isn't a semantic element for every possible thing you could do in HTML, you just have to use the one that is most relevant. 您在HTML中可能做的每一件事都没有一个语义元素,您只需要使用最相关的元素即可。 Depending on how you're going to be formatting this information, you should use either a table if the data is in a tabular format, or a list for pretty much any other format. 根据您将如何格式化此信息,如果数据以表格格式使用,则应使用表格,而对于几乎所有其他格式,则应使用列表。

You can style the list to remove the bullets at the side, but the bottom line is you're still providing a list of data, and that's the most semantic thing you could use. 您可以设置列表样式以删除侧面的项目符号,但最重要的是您仍在提供数据列表 ,这是您可以使用的最语义化的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM