哪一个更正确:< h1>< a> ...< / a>< / h1> OR<

编程入门 行业动态 更新时间:2024-10-23 07:17:24
本文介绍了哪一个更正确:< h1>< a> ...< / a>< / h1> OR< a>< h1> ...< / h1>< / a>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

< h1>< a ...> ...< / a>< / h1> 和< a ...>< h1> ...< / h1>< / a> 有效的HTML,还是只有一个正确?如果他们都是正确的,他们有不同的意义吗?

解决方案

我更新这个答案,因为旧的有点不正确。

正确答案是两个版本都是正确的。它们之间最大的区别在于,在< h1>< a> ..< / a>< / h1> 的情况下,只有标题中的文字将可点击。

如果您将< a> 放在< h1> code>和css display 属性是 block (默认情况下)整个块( < h1> 的高度以及< h1> 的容器宽度的100%将可点击。

从历史上看,您不能将块元素放入内联元素中,但HTML5不再是这种情况。我认为< h1>< a> ..< / a>< / h1>< / code>方法更传统。

如果您想在标题上放置锚点,比< a id =my-anchor>更好的方法;< h1> ..< / h1>< / a> 将会使用 id 或 name 这样的属性:< h1 id =my-anchor> ..< / h1> 或< h1 name =my-anchor> ..< / h1>

Are both <h1><a ...> ... </a></h1> and <a ...><h1> ... </h1></a> valid HTML, or is only one correct? If they are both correct, do they differ in meaning?

解决方案

I'm updating this answer since the old one was a bit incorrect.

The correct answer is that both versions are correct. The biggest difference between them is that in the case of <h1><a>..</a></h1> only the text in the title will be clickable.

If you put the <a> around the <h1> and the css display property is block (which it is by default) the entire block (the height of the <h1> and 100% of the width of the container the <h1> resides in) will be clickable.

Historically you could not put a block element inside of an inline element, but this is no longer the case with HTML5. I would think that the <h1><a>..</a></h1> approach is more conventional though.

In the case where you want to put an anchor on the header, a better approach than <a id="my-anchor"><h1>..</h1></a> would be to use either the id or the name attribute like this: <h1 id="my-anchor">..</h1> or <h1 name="my-anchor">..</h1>

更多推荐

哪一个更正确:&lt; h1&gt;&lt; a&gt; ...&lt; / a&gt;&lt; / h

本文发布于:2023-06-14 20:06:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/712525.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确   amp   lt   gt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!