Html <a> 标签中可以有 <p> 标签吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13911274/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can a <p> tag in <a> tag?
提问by jiguang
Possible Duplicate:
Is putting a div inside an anchor ever correct?
可能的重复:
将 div 放入锚点是否正确?
When we write some kind of 'product list', you need only one link, but it should contain product image, product name, product title etc. can we use a contain p or some other tag? is there any cross browser issue?
当我们写某种“产品列表”时,您只需要一个链接,但它应该包含产品图片、产品名称、产品标题等。我们可以使用包含 p 或其他标签吗?是否有任何跨浏览器问题?
I heard in html5, a tag can contain p tag, but still with no confidence about using it.
我听说在 html5 中,一个标签可以包含 p 标签,但仍然没有信心使用它。
some code like so:
一些像这样的代码:
<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">¥<span class="price">88.00</span</span>
<span class="fav">收藏</span>
</p>
<p><a class="fn" href="">基本商品单元的商品名称</a></p>
</a>
</li>
</ul>
回答by Quentin
In HTML 4.x (and earlier) and XHTML 1.x — No. <a>elements may not contain <p>elements.
在 HTML 4.x(及更早版本)和 XHTML 1.x 中——<a>不可以<p>。元素不能包含元素。
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: blockin your stylesheet.
在 HTML 5 中——<a>元素可能包含<p>元素,但浏览器对此有点不稳定,您可能会发现必须在样式表中显式设置<a>to display: block。
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.
问题中的代码还包含一个<a>里面的那个<p>. 这是不允许的。一个<a>元素可能不是另一个<a>元素的后代。
回答by Belyash
Inside atag can be tags with default display: inlineor inline-block. tags like span, em, strongetc.
内部a标签可以是带有 defaultdisplay: inline或inline-block. 标签,如span,em,strong等。
You can change your pto spanwith some class and write some styles in CSS for this class.
您可以使用某个类更改您的ptospan并为该类在 CSS 中编写一些样式。
P.S.: You can't use ainside a.
PS:a里面不能用a。
UPDATE:
更新:
<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">¥<span class="price">88.00</span</span>
<span class="fav">收藏</span>
</span>
<span class="fn">基本商品单元的商品名称</span>
</a>
</li>
</ul>

