提供XHTML和自动关闭标签 [英] Serving XHTML and self-closing tags

查看:75
本文介绍了提供XHTML和自动关闭标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建网站时,我尝试遵循xhtml 1.0严格标准.现在,validator.w3.org遵循XHTML 1.0 Strict标准来验证我的文档是否有效.这是一个代码示例:

 < div style ="color:#f00">< div style ="color:#00f"/>文本应为红色而不是蓝色. 

不幸的是,Firefox,Chrome和Internet Explorer错误地解析了文档:它们似乎都忽略了我的自关闭标签(主要是

  • 和其他一些标签)的关闭语句,从而错误地渲染了网站,文本为蓝色.如果我用

    替换

    标记,一切看起来都很好.我读了一下,并且根据xml文档(包括xhtml)可以自动关闭

    以下是文档随附的重要标头信息:

     <?xml version ="1.0" encoding ="UTF-8"吗?><!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" xml:lang ="zh-CN">< head>< meta http-equiv ="Content-Type" content ="application/xhtml + xml; charset = utf-8"/> 

    Apache2本身仍然发送Content-Type text/html,因为我还没有弄清楚如何覆盖.php mime类型,尽管中的信息应该以任何一种方式推翻.

    如何使用诸如

    之类的自动关闭标记,并通过常见的浏览器正确地对其进行解析?

    解决方案

    XHTML是使用XML的HTML,并且HTML没有像您显示的那样具有自动关闭标签.这适用于XHTML,但不适用于HTML,到目前为止,您还没有充当application/xml + xhtml.

    content-type元标记不会影响服务器为页面提供服务的方式,并且仅用于脱机使用.因此,根据情况,您必须在服务器中设置它或使用PHP进行设置.

    I am trying to follow the xhtml 1.0 strict standard as I am creating my website. Right now, validator.w3.org validates my document as valid, following the XHTML 1.0 Strict standard. Here is a code-example:

    <div style="color:#f00"><div style="color:#00f" />Text should be red and not blue</div>
    

    Unfortunately, Firefox, Chrome and Internet Explorer parses the document incorrectly: They all seem to ignore the closing statement of my self-closing tags (mostly <div />, <li /> and some other tags), thus rendering the site incorrectly, with the text being blue. if i replace <div /> tags with <div></div>, it all looks fine. I read about it and according to xml document, including xhtml, can be self-closed

    Here is the important header information that comes with the document:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!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" xml:lang="en">
            <head>
                <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
    

    Apache2 itself still sends Content-Type text/html, as I haven't figured out yet how to overwrite the .php mime type, though the info in <head> should overrule that either way.

    How can I use self-closing tags such as <div /> with them being parsed correctly by common browsers?

    解决方案

    XHTML is HTML using XML and HTML does not have self-closing tags like you show. This works in XHTML but not HTML and, so far, you are not serving as application/xml+xhtml.

    The content-type meta tag does not affect how the server serves the page and is for offline use only. So you must either set it in the server or with PHP, in your case.

    这篇关于提供XHTML和自动关闭标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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