Span inside anchor or anchor inside span or doesn't matter?
I want to nest span
and a
tags. Should I
<span>
inside <a>
<a>
inside <span>
3 - It doesn't matter.
BUT, I tend to only use a <span>
inside an <a>
if it's only for a part of the contents of the tag ie
<a href="#">some <span class="red">text</span></a>
Rather than:
<a href="#"><span class="red">some text</span></a>
Which should obviously just be:
<a href="#" class="red">some text</a>
It is perfectly valid (at least by HTML 4.01 and XHTML 1.0 standards) to nest either a <span>
inside an <a>
or an <a>
inside a <span>
.
Just to prove it to yourself, you can always check it out an the W3C MarkUp Validation Service
I tried validating:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Title</title>
</head>
<body>
<p>
<a href="http://www.google.com/"><span>Google</span></a>
</p>
</body>
</html>
And also the same as above, but with the <a>
inside the <span>
ie
<span><a href="http://www.google.com">Google</a></span>
with both HTML 4.01 and XHTML 1.0 doctypes, and both passed validation successfully!
Only thing to be aware of is to ensure that you close the tags in the correct order. So if you start with a <span>
then an <a>
, make sure you close the <a>
tag first before closing the <span>
and vice-versa.
这并不重要 - 他们都被允许进入对方。
链接地址: http://www.djcxy.com/p/36474.html上一篇: 文件附件在Microsoft Graph API中显示为消息实体
下一篇: 跨度内的锚或锚是跨度还是无关紧要?