0

我正在使用使用自定义标签的发布系统。这些在服务器上进行解释。问题是,当在本地查看时,它们会给 Opera 带来很大的问题(不会解释自定义标签)。

Opera 处理这些标签的方式与其他浏览器不同。看起来它正在关闭文档末尾的标签(即使标签包含右斜杠)。我只是想知道,如果这种行为被认为是错误或功能。

另外,如果您知道如何破解此类代码,以便我可以在本地调试 Opera 的 HTML+CSS(无需解释的自定义标签),请告诉我。谢谢你。

尝试以下代码以查看它的实际效果(现场示例):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Non-standard tag behavior in Opera</title>

    <style type="text/css" media="all">
        div { background: yellow; padding: 1em; }
        nonstandardtag { border: 1px solid red; }
    </style>

</head>

<body>

<div>
    <nonstandardtag>content of non-standard tag</nonstandardtag>
    main tag content
</div>

<div>
    <nonstandardtag />
    main tag content
</div>

</body>

</html>
4

5 回答 5

2

我使用歌剧超过 5 年。最接近标准的是浏览器。大多数在 Opera 中看起来很糟糕的网站都针对 IE 进行了“优化”。

但一个明显的问题是,为什么需要使用非标准标签?您可以将 div 和 span 标签用于几乎任何非标准解决方案。

于 2009-01-15T10:51:08.087 回答
2

Short: it's not a bug. Despite the DOCTYPE, your page is not interpreted as XHTML (and this is intentional).

HTML simply doesn't support the self-closing tag syntax the same way as XML.

In HTML, in practice <foo /> is the same as <foo> or <foo /="">. In theory it's same as <foo></foo>&gt;.

You need to tell browser to interpret page as X[HT]ML. DOCTYPE is not enough. To do this locally, file has to have .xml or .xhtml extension. When you serve file over HTTP, you must set Content-Type header to application/xhtml+xml or similar XML type (for static files usually .xhtml file extension does the job).

Your live example is served as text/html, so it won't be interpreted as XHTML, and won't work as you expect.

BTW: XHTML doesn't allow non-standard elements. If you want to add your own elements anyway, you should at least use your own namespace.

于 2009-03-15T20:50:54.660 回答
1

This seems to be fixed in Opera 10. So I guess it was not a feature.

于 2009-01-18T13:58:43.997 回答
0
于 2009-01-15T18:25:32.037 回答
0

Short answer: there are no guarentees or requirements on what a User Agent may do if you feed it malformed data.

于 2009-03-15T21:37:55.983 回答