简体   繁体   English

为什么我的网页无法使用 <!DOCTYPE html…> 但它与 <!DOCTYPE xhtml> ?

[英]Why does my webpage not work with <!DOCTYPE html…> but it works with <!DOCTYPE xhtml>?

I am making a web page and I am nearing completion, so I decided to put it through an html validator, and I had a bunch of errors with my page. 我正在制作一个网页,并且快要完成了,所以我决定将其放入html验证程序中,并且我的页面出现了很多错误。 My page works currently with <!DOCTYPE xhtml><html>... but when I type <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> my page's spacing breaks. 我的页面当前使用<!DOCTYPE xhtml><html>...但是当我键入<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">我页面的空格中断。

Examples: Picture of when it works 示例:工作时间的图片 它应该看起来像什么

Code: <!DOCTYPE xhtml> <html ng-app="ticTacToe" xmlns="http://www.w3.org/1999.xhtml"> 代码: <!DOCTYPE xhtml> <html ng-app="ticTacToe" xmlns="http://www.w3.org/1999.xhtml">

What happens when I add the proper code: 添加正确的代码后会发生什么: 在此处输入图片说明

Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html ng-app="ticTacToe" xmlns="http://www.w3.org/1999.xhtml"> 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html ng-app="ticTacToe" xmlns="http://www.w3.org/1999.xhtml">

So my question is, how can I make the spacing work, with the more valid code? 所以我的问题是,如何使用更有效的代码来使间距有效? It looks like the CSS selector "top: " that I am using is not working. 我正在使用的CSS选择器“ top:”似乎无法正常工作。 Any feedback will be greatly appreciated. 任何反馈将不胜感激。 Let me know if you need more info, thanks in advance! 如果您需要更多信息,请提前告诉我!

UPDATE: Direct CSS that is responsible for that part 更新:负责该部分的直接CSS

#bodyArea
{
    width: 425px;
    position: relative;
    top: 30%;
    left: 40%;
}

The answer to this question is validation . 这个问题的答案是验证

Run your page through the validator at http://validator.w3.org/ with both tags and note the differences. 使用两个标签通过验证器运行页面,网址为http://validator.w3.org/ ,并注意不同之处。

XHTML and HTML5 are different, so if the page is coded the same way, it is possible it will not render properly when you use an XHTML doctype. XHTML和HTML5不同,因此,如果页面的编码方式相同,则使用XHTML文档类型时可能无法正确呈现。

The doctype tells the browser how to interpret the code for the page. doctype告诉浏览器如何解释页面代码。 The HTML (or XHTML) should always validate to ensure your page displays properly over the greatest number of browsers. HTML(或XHTML)应始终进行验证,以确保您的页面在最多数量的浏览器上正确显示。

Reference for the differences: http://www.sitepoint.com/web-foundations/differences-html-xhtml/ 差异的参考: http : //www.sitepoint.com/web-foundations/differences-html-xhtml/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM