为什么这个自动关闭的TITLE标记破坏了我的网页 [英] why this self-closing TITLE tag breaks my web page

查看:67
本文介绍了为什么这个自动关闭的TITLE标记破坏了我的网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的网页.

I have a very simple webpage.

<html>
    <head>
        <title/>
    </head>
    <body>
    <h1>hello</h1>
    </body>
</html>

在Chrome和Firefox中都破坏了我的网页

breaks my webpage ,both in Chrome and Firefox

问题出在自动关闭标题标签,删除TITLE标签或添加标题解决了问题

the issue is with self-closing Title tag ,removing TITLE tag or adding a title fix the issue

<title>Test Page</title>

自动关闭的TITLE标签有什么问题,找不到任何引用来说明其无效

Whats the issues with self-closing TITLE tags , couldn't find any reference to say its invalid

推荐答案

如果您具有void元素:

If you have a void element:

<img />
<br />

那么他们就没有 内容 ,因为没有地方可以放.图像可以被认为是带有背景图像的空< div> .

与这些元素相比:

<h1>Hello</h1>
<section>World</section>

实际上包含的内容(在这种情况下为文字).

Which actually contain stuff (in this case, text).

< title/> 中断页面的原因是,您 需要 在网页中添加标题-如果您不这样做的话没有,它只会显示页面的网址,例如:

The reason that the <title/> breaks your page is because you need a title in a webpage - if you don't have one, it'll just display the URL of the page, for example:

google.com/index.html

您需要具有有效的标题,并且< title> 不是void元素.这就是为什么它会破裂.要查看此内容,请访问HTML验证网站(例如 https://validator.w3.org ),然后查看它告诉你.

You need to have a valid title, and <title> is not a void element. This is why it breaks. To see this, go to a HTML validation website (e.g. https://validator.w3.org) and see what it tells you.

简而言之-< title> 不是void元素-它需要一个开始和结束标记.

In short - <title> is not a void element - it requires an opening and closing tag.

研究显示我此网站,其中说:

Self-closing: No

因此,简而言之,它们不是自动关闭的元素.您可以在此处找到自闭合元素的列表.

So in short they're not self-closing elements. You can find a list of self-closing elements here.

这篇关于为什么这个自动关闭的TITLE标记破坏了我的网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆