Fczbkk
Fczbkk

Reputation: 1467

Non-standard tag behavior in Opera

I'm working with a publishing system that uses custom tags. These are interpreted on the server. The problem is, that they cause big problems with Opera, when viewed locally (custom tags are not interpreted).

Opera is handling these tags differently from other browser. It looks like it is closing the tag at the end of the document (even if the tag contains closing slash). I'm just wondering, if such behavior is considered bug or feature.

Also, if you have any idea how to hack such code so that I can debug HTML+CSS for Opera locally (without interpreted custom tags), please let me know. Thank you.

Try the folowing code to see it in action (live example):

<!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>

Upvotes: 0

Views: 452

Answers (5)

singpolyma
singpolyma

Reputation: 11262

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

Upvotes: 0

Kornel
Kornel

Reputation: 100200

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.

Upvotes: 2

Fczbkk
Fczbkk

Reputation: 1467

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

Upvotes: 1

Ms2ger
Ms2ger

Reputation: 15993

One, you don't need non-standard elements. Two, whatever you claim with your doctype, this isn't XHTML but HTML (as you make clear with the <meta http-equiv="Content-Type" content="text/html. That obviously means that browsers use their HTML parsers, and those don't (and shouldn't) support XML's shorthand syntax <element/> for empty elements.

Upvotes: 0

Toon Krijthe
Toon Krijthe

Reputation: 53476

I use opera for more than 5 years. It is the browser that approaches the standard the best. Most of the sites that look bad in Opera are "optimized" for IE.

But an obvious question is, why do you need to use nonstandard tags? You can use the div and span tags for almost any nonstandard solution.

Upvotes: 2

Related Questions