简体   繁体   English

我可以使用同一个锚链接到多个元素吗?

[英]Can I link to multiple elements with the same anchor?

I have blocks of code that needs to be linked to the same URL. 我有一些需要链接到同一URL的代码块。 For example, an ecommerce product listing. 例如,一个电子商务产品列表。 To save space, I would rather all of the objects be grouped in the same anchor rather than writing out the anchor 4+ times. 为了节省空间,我宁愿将所有对象分组在同一个锚中,而不是将锚写4次以上。 However, I do not know if this is best practice or functionally correct. 但是,我不知道这是最佳做法还是功能正确。

Can someone tell me if there is anything wrong with using the following code combination? 有人可以告诉我使用以下代码组合有什么问题吗? Functionally it works, but I don't know much about how this might perform across several browsers/platforms. 从功能上讲,它可以工作,但是我对在多个浏览器/平台上如何执行却不太了解。 At the moment it looks OK for me in Chrome, Firefox, Safari, IE9. 目前在Chrome,Firefox,Safari,IE9中对我来说看起来还可以。

    <a class="item" href="#">
        <img src="#" />
        <span class="brand">Brand</span>
        <span class="desc">Item</span>
        <span class="skue">123345</span>
        <span class="price">$4.79</span>
    </a>

And the CSS: 和CSS:

    .brand, .desc, .skue, .price {
        float:left;
        clear:both;
    }

Ideally, each of the item details (image, brand, description) will link to the same URL for that image. 理想情况下,每个商品详细信息(图片,品牌,说明)都将链接到该图片的相同URL。 Is there a better way of structuring this so it won't spit out a code with 5 different anchors? 有没有更好的结构化方式,这样它就不会吐出带有5个不同锚点的代码?

There is nothing wrong with this combination. 这种组合没有错。 You can perfectly wrap elements between an achor. 您可以在achor之间完美地包装元素。 As mentioned by Jon in the comments, it is meant for that. 正如乔恩(Jon)在评论中所提到的那样。

Here's an enumeration of elements that are allowed to go inside an <a> tag: 以下是允许放在<a>标记内的元素的枚举:

br | span | bdo | map
object | img | tt | i | b | big | small 
ins | del | script | input | select | textarea | label | button
em | strong | dfn | code | q |
samp | kbd | var | cite | abbr | acronym | sub | sup 

Source: http://www.w3.org/TR/xhtml1/dtds.html#dtdentry_xhtml1-strict.dtd_a.content 来源: http : //www.w3.org/TR/xhtml1/dtds.html#dtdentry_xhtml1-strict.dtd_a.content

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

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