是否需要在网页开始处添加HTML doctype [英] Is it neccessary to add HTML doctype at the starting of the web page

查看:140
本文介绍了是否需要在网页开始处添加HTML doctype的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否需要在HTML页面的起始处编写doctype?例如。



如果我使用此doctype并在HTML文件中:

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> 
< html>
< body>
< table width =95%height =100%border =0align =centercellpadding =0cellspacing =0bgcolor =#99FF66>
< tr>
< td>
< form id =loginname =loginFormaction =method =post>
< table align =centerborder =0cellspacing =0>

< tr>< td>使用者名称:< / td>< td>< input class =inputtextname =usernametype =textid =un />< / TD>< / TR>
< tr>< td>密码:< / td> < td>< input class =inputtextname =passwordtype =passwordid =pwd/>< / td> < / TR>

< tr>< td style =padding:0 0 0 3px> < input name =Submittype =submitclass =sbuttontabindex =4value =Login/>< / td>< / tr>
< / table>
< / form>
< / td>
< / tr>
< / table>




或者表单不在页面的中心(水平和垂直)。它只是水平居中。我想要两个。
如果我删除了上面的文档类型,那么表格将以这两个轴为中心。
请告诉我错在哪里。

解决方案

从技术上讲,不,你不需要 一个文档类型来获得某些东西在页面上显示。实际上,你绝对应该这样做。

文档类型本质上是一个协议,规定页面上的每个元素应该如何显示,哪些标签是有效的等。 / p>

doctypes的存在意味着可以根据此doctype开发Web浏览器,以确保它们正确呈现所有元素。



当文档类型不存在时,浏览器会解析HTML本身(通常称为怪癖模式)。尽管大多数现代浏览器对此做出了相当好的尝试(假设html的格式相对良好),但浏览器选择显示元素的方式仍然存在不一致之处。



简而言之,使用doctype意味着您可以依靠(大部分)页面在每个浏览器中呈现相同的内容,从而使开发工作变得更容易。


Is it neccessary to write doctype at the starting of the HTML page? E.g.

If I use this doctype and in the HTML file :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body >
    <table width="95%" height="100%"  border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#99FF66">
    <tr>
    <td>
<form id="login" name="loginForm" action="" method="post">    
          <table align="center" border="0" cellspacing="0">

               <tr><td>User Name:</td><td><input class="inputtext" name="username" type="text" id="un"/></td></tr>
               <tr><td>Password:</td>  <td><input class="inputtext" name="password" type="password" id="pwd"/></td>   </tr>

               <tr><td style="padding: 0 0 0 3px"> <input name="Submit" type="submit" class="sbutton" tabindex="4" value="Login" /></td></tr>
         </table>
 </form>
</td>
</tr>
</table>

The table or the form is not coming at the center (horizontal and vertical) of the page. It is just horizontally centered. I want both. If I remove the above doctype, then the table is centered on both the axis. Please tell where I am wrong.

解决方案

Technically, no, you dont need a doctype to get something to display on the page. In practice however, you definitely should.

A doctype is essentially a protocol that dictates how each element on the page should be displayed, which tags are valid etc. etc.

The existence of doctypes, means that web browsers can be developed against this doctype, to ensure they render all elements correctly.

When the doctype is not present, the browser resorts to interpreting the HTML itself (often called quirks mode). While most modern browsers make a fairly good attempt at this (provided the html is relatively well formed), there can still be inconsistencies the way browsers choose to display elements.

So in short, the use of a doctype means that you can rely (for the most part) on your page rendering the same in every browser, making development significantly easier.

这篇关于是否需要在网页开始处添加HTML doctype的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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