4

可能重复:
将 div 放入锚点是否正确?

当我们编写某种“产品列表”时,您只需要一个链接,但它应该包含产品图像、产品名称、产品标题等。我们可以使用包含 p 或其他标签吗?有没有跨浏览器的问题?

听说在html5中,一个标签可以包含p标签,但是还是没有信心使用它。

一些像这样的代码:

<ul class="xxx_list">  
<li class="hproduct">  
    <a href="#" class="url" title="" target="_blank">  
        <img class="photo" src="shoujike.jpg" alt="手机壳">  
        <p>  
            <span class="price_wrap">&yen;<span class="price">88.00</span</span>  
            <span class="fav">收藏</span>  
        </p>  
        <p><a class="fn" href="">基本商品单元的商品名称&lt;/a></p>  
    </a>  
</li>  
</ul>
4

2 回答 2

24

In HTML 4.x (and earlier) and XHTML 1.x — No. <a> elements may not contain <p> elements.

In HTML 5 — <a> elements may contain <p> elements, but browsers are a bit flaky about it and you may find you have to explicitly set the <a> to display: block in your stylesheet.

The code in the question also includes an <a> inside that <p>. This is not allowed. An <a> element may not be a descendant of another <a> element.

于 2012-12-17T09:21:46.737 回答
5

内部a标签可以是带有 defaultdisplay: inline或的标签inline-blockspan,em等标签strong

你可以用一些类来改变你p的,span并用 CSS 为这个类编写一些样式。

PS:你不能a在里面使用a

更新:

<ul class="xxx_list">  
    <li class="hproduct">  
        <a href="#" class="url" title="" target="_blank">  
            <img class="photo" src="shoujike.jpg" alt="手机壳">  
            <span class="some-class-name">  
                <span class="price_wrap">&yen;<span class="price">88.00</span</span>  
                <span class="fav">收藏</span>  
            </span>  
            <span class="fn">基本商品单元的商品名称&lt;/span>  
        </a>  
    </li>  
</ul>
于 2012-12-17T09:41:10.703 回答