<!DOCTYPE> 应该如何处理?在JSF中查看部分?HTML5 还是 XHTML? [英] How should a &lt;!DOCTYPE&gt; section look in JSF? HTML5 or XHTML?

查看:14
本文介绍了<!DOCTYPE> 应该如何处理?在JSF中查看部分?HTML5 还是 XHTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这只是我现在的好奇心.例如,在 Eclipse 中,这是在 New Facelet 模板 上定义的 部分,但对于大多数模板来说,这是相同的:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"xmlns:ui="http://java.sun.com/jsf/facelets"><头>..

我想使用更清晰的代码,所以我改为:

<html xmlns="http://www.w3.org/1999/xhtml"xmlns:ui="http://java.sun.com/jsf/facelets"><头>..

它在开发中运行良好,但我想知道这种方法在未来通过许多浏览器或设备(移动)是否会出现任何问题.

解决方案

这是 HTML5 文档类型,它应该可以在所有浏览器中正常工作,包括 IE6.

JSF 被正式指定用于生成符合 XHTML 1.0 的标记(使用

  • 是否可以将 JSF+Facelets 与HTML 4/5?
  • 我应该从 HTML 还是 XHTML 开始?
  • It's just a curiosity I'm having right now. In Eclipse this is the <head> section that came defined on a New Facelet Template for instance, but for the most template is the same thing :

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets">
    <head>
      ..
    </head>
    

    I would like to user a more clear code on it, so I change to :

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets">
    <head>
      ..
    </head>
    

    It works fine in development, but I was wondering if this kind of approach would give any problem in the future, through the many browsers or device (mobile).

    解决方案

    That's the HTML5 doctype and it should work just fine in all browsers, including IE6.

    JSF is officially specified to produce XHTML 1.0 compliant markup (with here and there only a few violations in the implementations which is fixed in JSF 2.2 and/or are manageable by context params). JSF can by design not produce non-XML sytnax (e.g. <br> instead of <br/>) and therefore the old HTML4 doctype is in no way compatible with JSF-produced HTML output (that is, when you respect the standards and/or fear the W3 validator; however, most if not all browsers are very forgiving on it). In contrary to the old HTML4 doctype, the HTML5 doctype allows XML syntax and is therefore compatible with XHTML doctypes. JSF pages can therefore be authored with HTML5 doctype.

    The doctype is only of importance for how the webbrowser interprets and presents the HTML markup (as produced by JSF in your specific case, but the HTML does not necessarily need to be produced by JSF and thus browser's presentation is technically completely unrelated to JSF). Escpecially Microsoft IE has a major problem with certain doctypes or a complete lack of doctype. At the bottom of this page you can find a concise overview of browser behaviour in combination with certain doctypes. There are three standard behaviours:

    • Q - Quirksmode. You really don't want to have that. It triggers box model bug in IE. The CSS width and height then incorrectly covers the padding and border.
    • A - Almost standards mode. Affordable, only vertical sizing of table cells is not as per CSS2 spec. Useful if you want to avoid mysterious gaps of images in table cells.
    • S - Standards mode. Browser tries to be fully w3 HTML/CSS standard compliant. Preferred mode since it's the only mode you can be less or more certain that your website will look exactly the same in all browsers.

    In your particular case, with the change from XHTML 1.0 transitional doctype to HTML5 doctype, Firefox, Chrome, Safari and IE>=8 will go from "A" to "S". So, you should definitely review the browser's presentation of your website as to padding of images in table cells if you intend a pixel-perfect design.

    As to the importance of the doctype in IE, here's a piece of HTML which demonstrates the box model bug triggered by "Q" in IE6-9 (note that this does not manifest in IE10 anymore):

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <title>Remove DOCTYPE to trigger quirksmode</title>
            <style>
                #box { 
                    background: yellow; 
                    width: 100px;
                    padding: 20px; 
                    border: 20px solid black; 
                    margin: 20px;
                }
            </style>
        </head>
        <body>
            <div id="box">box</div>
        </body>
    </html>
    

    Copy'n'paste'n'run it. With <!DOCTYPE html> present, you'll see a rectangle. Without the doctype line you'll see a genuine square (in IE10 you need in the webdeveloper toolset (press F12) to change the "Browser mode" to e.g. IE9 in order to see it).

    See also:

    这篇关于<!DOCTYPE> 应该如何处理?在JSF中查看部分?HTML5 还是 XHTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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