简体   繁体   English

我们可以补充吗? <ul> 里面的<a>标签?</a>

[英]can we add <ul> inside <a> tag?

when im writing html code inside of anchor tag, my dreamweaver editor showing bug in anchor tag. 当我在锚标签内写html代码时,我的dreamweaver编辑器显示锚标记中的错误。 Shouldnt use inside tag? 不应该使用内部标签? Is there any rules writing/using tags ? 是否有编写/使用标签的规则?

I am using Html 5. This is my code. 我使用的是Html 5.这是我的代码。 http://jsfiddle.net/CfPnj/ http://jsfiddle.net/CfPnj/

In HTML5, you can put block elements insize <a> elements. 在HTML5中,您可以将块元素放入<a>元素中。 See http://dev.w3.org/html5/markup/a.html#a-changes http://dev.w3.org/html5/markup/a.html#a-changes
This is new in HTML5. 这是HTML5中的新功能。 In any other version of HTML, it's illegal. 在任何其他版本的HTML中,它都是非法的。

Update (added later, when I understood HTML5 better) 更新(稍后添加,当我更好地理解HTML5时)

This is because <a> 's content model was changed from inline to transparent. 这是因为<a>的内容模型已从内联更改为透明。 In other words, what you can put inside an <a> is now the same as what you can put in <a> 's parent. 换句话说,你可以放在<a>内容现在与你可以放在<a>父级中的内容相同。 The actual answer to the question here is, "it depends". 这里问题的实际答案是“它取决于”。
For instance, 例如,

<div><a><ul><li></ul></a></div>

is perfectly valid HTML5, while 是完全有效的HTML5,而

<span><a><ul><li></ul></a></span>

is not (because span is an inline element). 不是(因为span是内联元素)。
Hope this helps! 希望这可以帮助!

<ul> is a block element tag, and <a> is an inline element tag - and block element tags should never go inside inline element tags, only the other way around (or inline element tags inside other inline element tags)... <ul>是块元素标记, <a>是内联元素标记 - 块元素标记永远不应该进入内联元素标记,只能反过来(或其他内联元素标记内的内联元素标记)......

Start here, and then google for more: http://line25.com/articles/10-html-tag-crimes-you-really-shouldnt-commit 从这里开始,然后谷歌了解更多信息: http//line25.com/articles/10-html-tag-crimes-you-really-shouldnt-commit

In general, inline elements only allow other inline elments as children. 通常,内联元素仅允许其他内联元素作为子元素。 If you check the HTML 4.01 Doctype Definition , you will see that this is indeed the case for <a> tags (line 342). 如果您检查HTML 4.01 Doctype Definition ,您会看到<a>标签确实如此(第342行)。 Your IDE is correct to mark a <ul> tag inside an <a> tag as invalid, although most browsers will still 'do the right thing'. 您的IDE将<a>标记内的<ul>标记标记为无效是正确的,尽管大多数浏览器仍然会“做正确的事情”。

Are you trying to do something like this: 你想做这样的事情:

<a href="google.com">
    <ul>
        <li>Google.com</li>
        <li>Gmail.com</li>
    </ul>
</a>​

Its syntactically right as per HTML rules, well since HTML does not show any error thus it is showed up as bug in your dreamweaver. 它在语法上符合HTML规则,因为HTML没有显示任何error因此它在你的Dreamweaver中显示为bug

It will sowing something like this: 它将播种这样的东西:

- Google.com - Google.com
- Gmail.com - Gmail.com

But both the links have same location google.com . 但这两个链接都有相同的位置google.com

I thought you are trying to do something like this: 我以为你正在尝试这样做:

<ul>
    <li><a href="google.com">Google.com</a></li>
    <li><a href="stackoverflow.com">stackoverflow.com</a></li>
</ul>

It will be rendered as: 它将呈现为:

And that is without any bug.. 这没有任何错误..

您不必将代码放在锚链接中,因为当您单击链接时,您将被重定向到锚点的顶部,因此您不需要在<a>编写所有代码

According to http://validator.w3.org this is valid in HTML5 根据http://validator.w3.org,这在HTML5中有效

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>title</title>
  </head>
  <body>
     <a href="#"><ul><li>foo</li></ul></a>
  </body>
</html>

but not in HTML4.1 (strict) 但不是HTML4.1(严格)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
  <html lang="en">
    <head>
      <title>title</title>
    </head>
    <body>
      <p>
        <a href="#"><ul><li>foo</li></ul></a>
      </p>
   </body>
  </html>

but it doesn't feel right semantically (to me) to do this :-) 但是在语义上(对我来说)这样做感觉不对:-)

Looking at the specification a <ul> is allowed Where flow content is expected and <a> is categorized as flow content . 查看规范时, 允许使用<ul> 其中流内容是预期的<a> 被分类流内容

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

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