“内容”属性对< span>有效标签>如果是的话,这是一个很好的做法? [英] Is the "content" attribute valid for the <span> tag > if so is it a good practice?

查看:80
本文介绍了“内容”属性对< span>有效标签>如果是的话,这是一个很好的做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

content属性对于 span 标签有效吗?如果是的话,这是一个很好的做法?
我将在我的网页上应用微数据(schema.org)。



我想在我的页面的某些元素上添加微数据。

>

这是我目前的代码:

 < span itemscope itemtype =http ://schema.org/Product> 
< span itemprop =name> CryptoMate64 USB Cryptographic Token< / span>
< span class =hidden>
< span itemprop =productid/> 286< / span>
< span itemprop =modelcontent =ACOS5T-B2-SCZ/> ACOS5T-B2-SCZ< / span>
< / span>
< / a>
< / span>

正如您所看到的,我有一个 div 类中隐藏,因为模型和id不应该显示在页面上。



我想通过这样来缩小代码:

 < span itemscope itemtype =http://schema.org/Product> 
< span itemprop =name> CryptoMate64 USB Cryptographic Token< / span>
< span itemprop =productidcontent =286/>& nbsp;< / span>
< span itemprop =modelcontent =ACOS5T-B2-SCZ/>& nbsp;< / span>
< / a>
< / span>

我可以使用 meta 而不是 span ,以便内容不可见。但我认为这不是一个好的做法,因为我会有很多项目。你有什么建议?谢谢。


$ b

解决方案

$ b

HTML5和Microdata都没有为 span 定义 content 属性。 ( RDFa ),但你没有使用它。)



如果您希望使用Microdata标记不应该显示的内容,则可以使用常规HTML并使用CSS隐藏它,或者 li>

  • 使用 link 元素(用于URI)和 meta 元素(用于其他任何内容) ;这两个元素都在允许在 body 中,并且通常默认隐藏浏览器样式表。



  • 我更喜欢后一种变体( meta / link ),但每次都不可能(例如,如果需要使用 itemscope 添加新项目)。


    Is the "content" attribute valid for span tag? If so is it a good practice? I'll be applying microdata (schema.org) on my site pages.

    I want to add microdata on some elements of my page.

    This is my current code:

        <span itemscope itemtype="http://schema.org/Product">
            <a itemprop="url" class="list-items" href="/product/286/cryptomate64-usb-cryptographic-token/" title="CryptoMate64 USB Cryptographic Token">
                <span itemprop="name">CryptoMate64 USB Cryptographic Token</span>
                <span class="hidden">
                    <span itemprop="productid"/>286</span>
                    <span itemprop="model" content="ACOS5T-B2-SCZ" />ACOS5T-B2-SCZ</span>
                </span>
            </a>    
        </span>
    

    As you can see, I have a div with class "hidden" there because the model and id shouldn't be displayed on the page.

    I want to minify the code by doing this:

    <span itemscope itemtype="http://schema.org/Product">
        <a itemprop="url" class="list-items" href="/product/286/cryptomate64-usb-cryptographic-token/" title="CryptoMate64 USB Cryptographic Token">
            <span itemprop="name">CryptoMate64 USB Cryptographic Token</span>
            <span itemprop="productid" content="286" />&nbsp;</span>
            <span itemprop="model" content="ACOS5T-B2-SCZ" />&nbsp;</span>
        </a>    
    </span>
    

    I can use meta instead of span so that the content is not visible. But I think it won't be a good practice since I'll be having a lot of items. What can you suggest? Thanks.

    解决方案

    No, it’s not valid.

    Neither HTML5 nor Microdata define a content attribute for span. (RDFa does, but you are not using it.)

    If you want to markup content with Microdata that should not be visible, either

    • use usual HTML and hide it with CSS, or
    • use link elements (for URIs) and meta elements (for anything else); both elements are allowed in the body, and typically hidden by default browser stylesheets.

    I’d prefer the latter variant (meta/link), but it’s not possible everytime (e.g., if you need to add new items with itemscope).

    这篇关于“内容”属性对&lt; span&gt;有效标签&gt;如果是的话,这是一个很好的做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆