我们可以使用< a>吗?直接在体内,还是应该始终在任何块级标签中?参见示例(XHTML) [英] Can we use <a> directly in the body, or it should always in any block level tag? See example (XHTML)

查看:59
本文介绍了我们可以使用< a>吗?直接在体内,还是应该始终在任何块级标签中?参见示例(XHTML)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪个是对的?这个:

<h2>heading 2</h2>
<p><a href="#" target="_blank" title="Opens in a new window">link 1</a></p>
<h2>heading 2 </h2>
<p><a href="#" target="_blank" title="Opens in a new window">link 2</a></p>
<h2>heading 2 </h2>
<p><a href="#" target="_blank" title="Opens in a new window">link 3</a></p>
<h2>heading 2 </h2>
<p><a href="#" target="_blank" title="Opens in a new window">link 4</a></p>

或者这个:

<h2>heading 2</h2>
<a href="#" target="_blank" title="Opens in a new window">link 1</a>
<h2>heading 2 </h2>
<a href="#" target="_blank" title="Opens in a new window">link 2</a>
<h2>heading 2 </h2>
<a href="#" target="_blank" title="Opens in a new window">link 3</a>
<h2>heading 2 </h2>
<a href="#" target="_blank" title="Opens in a new window">link 4</a>

推荐答案

@Jitendra,我同意您的观点..但仅当您使用strict.dtd(HTML/XHTML)
根据W3C建议(对于 strict dtd )..标签< a> 必须在块元素中使用.

看下面的例子:

@Jitendra, I agree with your point .. but only if you are using strict.dtd (HTML/XHTML)
According to W3C recommendation(for strict dtd) .. the tag <a> must be used in a block element.

Look at the following example:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
 <head>
   <meta content="text/html; charset=utf-8" http-equiv="content-type"/>
   <title>example</title>
 </head>
 <body>You don't have sufficient privileges to access the page.<a href="www.google.co.in">Click here</a> to go back.
 </body>
</html>

上面的代码在执行HTML验证时会产生错误.

The above code produces error while doing HTML validation .. saying

document type does not allow element "A" here; missing one of "P", "H1", "H2", "H3", "H4", "H5", "H6", "PRE", "DIV", "ADDRESS" start-tag

使dtd处于松散/过渡状态,您可以摆脱此错误..对于严格HTML或严格XHTML,此错误很明显..

Making the dtd as loose/transitional you can get rid of the error .. For Strict HTML or Strict XHTML this error is obvious ..

希望它对您有所帮助..:)

Hope it helped .. :)

Regards-Infant Pro

regards-Infant Pro

这篇关于我们可以使用&lt; a&gt;吗?直接在体内,还是应该始终在任何块级标签中?参见示例(XHTML)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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