了解最简单的HTML页面 [英] Understanding simplest HTML page

查看:65
本文介绍了了解最简单的HTML页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力更好地理解简单的HTML,但是我发现有冲突的信息很常见。不仅如此,即使是看起来很简单且没有任何出错的可能,也不会出现任何错误。

看起来我处于非常不稳定的状态。


例如,几乎所有关于html的书籍和网络课程我都会读取b
告诉我必须包含< html>,< head>和< body>标签对。


我一直这样做,从不质疑它。看起来很完美

对我来说是合理的(并且仍然如此)将元信息从

呈现的内容中分离出来,并且确实要求浏览器被告知

内容是html。虽然我猜服务器存在mime类型

text / html包含内容是否为html,以及是否有doctype。


但是在阅读 http://www.w3.org/TR/html401/struct/global .html

注意到html,head和body标签是可选的(虽然需要

标题标签)。所以我做了一个测试页


<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.01 // EN"

" http ://www.w3.org/TR/html4/strict.dtd">

< title>测试头部是否需要< / title>

< META HTTP-EQUIV =内容类型 CONTENT =" text / html的; charset = ISO-8859-1">

< p>文本段落


此验证无任何警告。

如果你遗漏了标题或某些正文内容,它将无法验证。因此,验证者至少要假设

是头部,什么是身体。我想大多数用户代理解析器也会支付



有没有人对html的好教程文本有任何建议

一切正确吗?目前我正在逐步浏览W3C文档,但我倾向于发现自己错过了一些

的含义。


-
http://www.ericlindsay.com

解决方案

在我们的上一集中,

< NO **************** ****************@freenews.iinet .net.au> ;,

可爱而有才华的Eric Lindsay播出

comp.infosystems。 www.authoring.html:

我一直在努力更好地理解简单的HTML,但是我发现相互矛盾的信息很常见。不仅如此,即使是看似基本的,没有任何出错的可能性
看起来我处于非常不稳定的状态。
例如,我所阅读的html上的每本书和网络课程都告诉我必须包含< html>,< head>和< body>标签对。


学习阅读DTD和阅读你正在使用的DTD的b $ b将会容易得多。


在许多html DTD中,实际需要的唯一标签是

< title>< / title>。可以暗示html,head和body标签。


文档中第一个不能成为头元素的东西是

假设关闭头部元素并打开body元素。如果

你有一些流浪的纯文本,你认为是头部

元素,它会关闭head元素并打开body元素,

因此,如果你有< / head>< body>标签后面的标签,

验证器或lints会抱怨。

我一直这样做,从不质疑它。对于我(并且仍然如此)来说,从显示的内容中分离元信息似乎是完全合理的,并且确实要求浏览器被告知
内容是html。虽然我猜服务器存在mime类型
text / html涵盖内容是否为html,如同拥有doctype一样。
但是在阅读 http://www.w3 .org / TR / html401 / struct / global.html 我注意到html,head和body标签是可选的(虽然需要
标题标签)。所以我做了一个测试页
<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.01 // EN"
" http://www.w3.org/TR/html4 /strict.dtd">
< title>测试head中是否需要< / title>
< META HTTP-EQUIV =" Content-Type" CONTENT =" text / html的; charset = ISO-8859-1">
< p>文本段落
此验证无任何警告。


对。就像它应该的那样。 < p为H.原因< / head>< body>

暗示。 (推断,对于英语专业。)

如果你遗漏了标题或某些正文内容,它将无法验证。所以验证者至少要假设头部是什么,身体是什么。我想大多数用户代理解析器也会。
有没有人对有关html
的好教程文本有任何建议,以确保一切正确?目前我正在逐步浏览W3C文档,但我发现自己错过了一些
含义。




我如果你学会了读这些DTD,那么这些东西就容易多了。你为你的文件申报的DTD是

法律,其他一切都是评论 - 其中一些是

不可靠的评论。建立适当嵌套显式标签的习惯是很好的建议,即使其中一些可能是暗示的b $ b。但是,如果您知道可能隐含了哪些标记,那么理解验证器

输出会更容易。对于

示例,如果验证器告诉您您试图在文档正文中放置元

,则可能会查看您的文档

很长一段时间检查所有的元数是否在

< / head>之前没有意识到验证器试图告诉

你在< head>< / head>里面有一些流浪的身体元素(可能是纯粹的

文本)在元标记之前。这导致

验证器推断< / head>所以下面的元标记看起来像

它在体内。


例如,你得到这样的东西:


onsgmls:joe.tmp:7:78:E:文档类型不允许元素LINK这里

onsgmls:joe.tmp:8:6:E:元素HEAD的结束标记没有打开

onsgmls:joe.tmp:9:5:E:文档类型不允许元素BODY这里


文件是这样的:


<!DOCTYPE html PUBLIC" - // W3C // DTD HTML 4.01 Transitional // EN"

" http://www.w3.org/TR/html4/loose.dtd">

< html lang =" zh -us">

< head>

< title>示例< / title>世界!

< link的rel ="开始" HREF =" index.html的" title =" My Index" type =" text / html" lang =" en">

< / head>

< body>


< p>嘿,y''all< / p>


< / body>

< / html>


嗯,很容易发现世界!在这个简单的

例子中。关闭头部元素并打开身体

元素。结果链接在body元素中,no-no,

有一个< / head>在头部关闭并且< body>之后当

的身体已经打开时(另一个< body>是不允许的)。在一个

林中的链接,meta和可能的脚本元素中,一些

丢失纯文本字符可能很难被发现,如果你

不知道验证器试图告诉你什么,你

甚至不知道该找什么。

有关如何获取的信息阅读DTD在这里:


< http://www.w3.org/TR/REC-html40/intro/sgmltut.html>

- -

Lars Eighner us****@larseighner.com http://www.larseighner.com/

我没见过其他人因为巨人站在我的肩膀上。


Lars Eighner写道:


对。就像它应该的那样。 < p为H.原因< / head>< body>是暗示的。 (推断,对于英语专业。)



" Implied"是正确的。渲染引擎会推断它。


-

jmm(连字符)列表(at)sohnen-moe(点)com

(删除电子邮件的.AXSPAMGN)


文章< sl ******************** @ goodwill.io.com>,

Lars Eighner< us **** @ larseighner.com>写道:

有关如何阅读DTD的信息,请访问:

< http://www.w3.org/TR/REC-html40/intro /sgmltut.html>




感谢Lars的例子。我实际上已经去过读取DTD的页面了

,但到那时我的脑袋已经满了,所以我只是b
浏览它并将其加入书签以供日后使用。我已经在

浏览器中打开了它,明天我会仔细阅读它。


我还是会喜欢一个更简单的文字,如果有的话存在。特别是写作

a有效且正确的网页似乎不足以确保

所有浏览器都能应对。


- -
http://www.ericlindsay.com


I have been trying to get a better understanding of simple HTML, but I
am finding conflicting information is very common. Not only that, even
in what seemed elementary and without any possibility of getting wrong
it seems I am on very shaky ground .

For example, pretty much every book and web course on html that I have
read tells me I must include <html>, <head> and <body> tag pairs.

I have always done that, and never questioned it. It seemed perfectly
reasonable to me (and still does) to split meta information from
presented content, and indeed to require that browsers be told the
content was html. Although I guess having a server present mime type
text/html covers whether contents are html, as does having a doctype.

However on reading http://www.w3.org/TR/html401/struct/global.html I
noticed that the html, head and body tags were optional (although the
title tag is required). So I did a test page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<title>Test whether required in head</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<p>Paragraph of text

This validates without any warning.

If you leave out either the title or some body content it will not
validate. So the validator at least is making an assumption about what
is head and what is body. I would imagine most user agent parsers would
also.

Does anyone have any suggestions about good tutorial texts about html
that get everything correct? At the moment I am gradually going through
the W3C documentation, but I tend to find myself missing some of the
implications.

--
http://www.ericlindsay.com

解决方案

In our last episode,
<NO********************************@freenews.iinet .net.au>, the
lovely and talented Eric Lindsay broadcast on
comp.infosystems.www.authoring.html:

I have been trying to get a better understanding of simple HTML, but I
am finding conflicting information is very common. Not only that, even
in what seemed elementary and without any possibility of getting wrong
it seems I am on very shaky ground . For example, pretty much every book and web course on html that I have
read tells me I must include <html>, <head> and <body> tag pairs.
It would be a lot easier just to learn to read DTDs and to read
the DTD you are using.

In many html DTDs the only tags actually required are
<title></title>. The html, head, and body tags can be implied.

The first thing in a document that cannot be a head element is
assumed to close the head element and open the body element. If
you have a bit of stray plain text in what you think is the head
element, it closes the head element and opens the body element,
and thus if you have </head><body> tags later in the document,
validators or lints will complain.
I have always done that, and never questioned it. It seemed perfectly
reasonable to me (and still does) to split meta information from
presented content, and indeed to require that browsers be told the
content was html. Although I guess having a server present mime type
text/html covers whether contents are html, as does having a doctype. However on reading http://www.w3.org/TR/html401/struct/global.html I
noticed that the html, head and body tags were optional (although the
title tag is required). So I did a test page <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<title>Test whether required in head</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<p>Paragraph of text This validates without any warning.
Right. Just as it should. <p> causes </head><body> to be
implied. (Inferred, for English majors.)
If you leave out either the title or some body content it will not
validate. So the validator at least is making an assumption about what
is head and what is body. I would imagine most user agent parsers would
also. Does anyone have any suggestions about good tutorial texts about html
that get everything correct? At the moment I am gradually going through
the W3C documentation, but I tend to find myself missing some of the
implications.



As I have said, these things are much easier if you learn to
read the DTDs. The DTD you declare for your document is the
law, and everything else is commentary -- and some of it is
unreliable commentary. It is good advice to form the habit of
properly nesting explicit tags, even when some of them could be
implied. But it makes it a lot easier to understand validator
output if you know what tags might have been implied. For
example, if the validator tells you that you tried to put a meta
in the body of your document, you might go over your document
for a long time checking that all the metas were before the
</head> without realizing that the validator is trying to tell
that you have some stray body element (which might be plain
text) inside <head></head> before a meta tag. That caused the
validator to infer </head> so the following meta tag looked like
it was in the body.

For example, you get something like this:

onsgmls:joe.tmp:7:78:E: document type does not allow element "LINK" here
onsgmls:joe.tmp:8:6:E: end tag for element "HEAD" which is not open
onsgmls:joe.tmp:9:5:E: document type does not allow element "BODY" here

The document is something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en-us">
<head>
<title>An Example</title>Hi, world!
<link rel="start" href="index.html" title="My Index"type="text/html" lang="en">
</head>
<body>

<p>Hey, y''all</p>

</body>
</html>

Well, it is easy enough to spot the Hi, world! in this simple
example. That closed the head element and opened the body
element. As a result link is in the body element, a no-no,
There is a </head> after the head is closed and <body> when the
body is already open (and another <body> is not allowed). In a
forest of link, meta, and possibly script elements, a couple of
lose plain-text characters might be hard to spot, and if you
didn''t know what the validator was trying to tell you, you
wouldn''t even know what to look for.
Information on how to read DTDs is here:

<http://www.w3.org/TR/REC-html40/intro/sgmltut.html>
--
Lars Eighner us****@larseighner.com http://www.larseighner.com/
I have not seen as far as others because giants were standing on my shoulders.


Lars Eighner wrote:


Right. Just as it should. <p> causes </head><body> to be
implied. (Inferred, for English majors.)


"Implied" is correct. The rendering engine would infer it.

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)


In article <sl********************@goodwill.io.com>,
Lars Eighner <us****@larseighner.com> wrote:

Information on how to read DTDs is here:

<http://www.w3.org/TR/REC-html40/intro/sgmltut.html>



Thanks for the examples Lars. I had actually been to the page on
reading the DTDs, but by then my head was already full, so I only
skimmed it and bookmarked it for later. I''ve left it open in the
browser and I''ll read it carefully tomorrow.

I would still like an easier text, if one exists. Especially as writing
a valid and correct web page does not seem a sufficient skill to ensure
all browsers will cope.

--
http://www.ericlindsay.com


这篇关于了解最简单的HTML页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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