h1 and the span(h1 和跨度)
问题描述
在我的 html 中使用 h1-h6 标签时,我不断收到关于 w3c 验证器的错误消息.我是新手,我已经尝试了很多次来解决这个问题,但我不能.
While using h1-h6 tags in my html, i keep getting error messages on w3c validator. I'm new to this and I've tried so many times to solve the problem but i can't.
文本在我的网站上看起来非常好,但无法验证.我该如何解决这个问题?错误信息如下;
The text appears perfectly fine on my website but it won't validate. How do i solve this problem? The error message is as follows;
第 34 行,第 4 列:文档类型不允许元素h1"这里;失踪对象"、小程序"、地图"之一,iframe"、按钮"、ins"、del"开始标签
Line 34, Column 4: document type does not allow element "h1" here; missing one of "object", "applet", "map", "iframe", "button", "ins", "del" start-tag
<h1><span>我的网站</h1><span>
<----这是我得到错误的代码.
<h1><span> My website </h1>< span>
<----this is the code i'm getting the error for.
提到的元素是不允许的出现在上下文中你已经放置了它;另一个提到的元素是唯一的两者都允许在那里并且可以包含提到的元素.这可能意味着你需要一个包含元素,或者可能你忘记了关闭前一个元素.
The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.
此消息的一个可能原因是您试图将块级元素(例如
"或")放入内联元素(例如"、";"或").
One possible cause for this message is that you have attempted to put a block-level element (such as "
" or "") inside an inline element (such as "", "", or "").
无论如何,使用标题标签的最佳方式是什么?我做错了什么?
In any case what's the best way to use header tags? What am I doing wrong?
推荐答案
- span 是一个内联元素
- h1 是块元素
- 内联元素不能包含块元素
- 元素不能部分被其他元素包含
- An span is an inline element
- An h1 is a block element
- An inline element cannot contain a block element
- Elements cannot be partially contained by other elements
因此,从DTD的角度来看:
Therefore, from the perspective of the DTD:
<h1><span>…</span></h1> <!-- This is fine -->
<div><h1>…</h1></div> <!-- This is fine -->
<h1><span>…</h1></span> <!-- This is wrong -->
<span><h1>…</h1></span> <!-- This is wrong -->
问题的正确解决方案实际上取决于您尝试使用 span 的目的.
What the right solution to the problem actually is rather depends on what you are trying to use the span for.
(请注意,上面对块和内联元素的讨论有些简化.请参阅 如何阅读 HTML DTD 以获得完整的故事,尤其是内容模型部分)
(Note that the discussion of block and inline elements above is somewhat simplified. See How to read the HTML DTD for the full story, in particular the section on the Content Model)
这篇关于h1 和跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:h1 和跨度
基础教程推荐
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01