h1 和跨度

2023-09-07前端开发问题
2

本文介绍了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 和跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

      The End

相关推荐

layui 实现实时刷新一个外部的div
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14 前端开发问题
156

layui tree树组件怎么自定义添加图标
经常用到layui的朋友都知道,layui tree默认是不能自定义图标的,那么我们要自定义的话要怎么操作呢? 首先用编辑器软件(修改时候用编辑器记得编码),打开layui.js。搜索: i class="layui-icon layui-icon-file" 改为如下代码: i class="'+ (i.icon || "l...
2024-10-26 前端开发问题
493

layui要如何改变时间日历布局大小?
问题描述 我想改变layui时间日历布局大小,这个要怎么操作呢? 解决办法 可以用css样式对时间日历进行重新布局,具体代码如下: !DOCTYPE htmlhtmlheadmeta charset="UTF-8"title/titlelink rel="stylesheet" href="../../layui/css/layui.css" /style#test-...
2024-10-24 前端开发问题
271

jQuery怎么动态向页面添加代码?
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18 前端开发问题
125

“数组中的每个孩子都应该有一个唯一的 key prop"仅在第一次呈现页面时
quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)...
2024-04-20 前端开发问题
5

CoffeeScript 总是以匿名函数返回
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)...
2024-04-20 前端开发问题
13