zoukankan      html  css  js  c++  java
  • Why does invalid HTML work?(转载) Anny

    By Jennifer Kyrnin, About.com Guide
    Question: Why does invalid HTML work?

    One of the number one reasons why people don't validate is because when they test, the page seems to be displaying without a problem. Why is it that Web browsers will display HTML that is technically incorrect? Does that mean that we shouldn't need to worry about valid or correct HTML (or CSS or JavaScript or PHP, etc.)?

    Answer:

    When Web browsers were invented, the programmers recognized that there was a possibility that there would be hundreds if not thousands of people writing HTML and creating Web pages. When this many people (and there are significantly more than that now) are trying to use a programming language or markup language like HTML, it can get very frustrating very quickly if every tiny error results in a broken page. So the Web browser programmers decided that browsers should be forgiving.

    What this means is that when a Web browser views a Web page, it has the rules for HTML (and CSS and JavaScript) and attempts to interpret them to display your Web page. But if it comes across something unexpected, incorrect, or from an older specification, the browser ignores it or tries to guess at what the designer wants.

    This means that a novice or lazy designer can get away with incorrect code and have pages that display in the browser window without a problem. Some errors are minor, such as leaving off the alt attribute in an image tag. Technically, this is invalid, but the browser displays the image anyway. Some errors are bigger, such as leaving off the closing table tag. In older versions of Netscape, before it got more forgiving, this would cause a table and everything after it in the HTML, to simply disappear. While that is noticeable, Internet Explorer didn't mind the missing table tag and would display the page. So many designers who did this wouldn't test in Netscape and wouldn't know of the problem for long periods of time.

    So Why Bother with Valid HTML?

    While browsers will attempt to display your HTML even if there are errors, there are some good reasons to validate your HTML:

    • While the HTML may display, it may display differently than if it were written correctly.
    • Errors will compound with one another. One error may display fine, two might have a slight problem, and 5-10 might cause the page to display completely incorrectly.
    • While most modern browsers are forgiving, newer user agents like cell phones, PDAs and so on may not be as forgiving. Broken pages will lose you readers.
    • Invalid HTML, especially if it's been deprecated, may not be supported by browsers in the future. So, while the <font> tag works right now, future browsers might not support it, and then your pages using that tag will no longer work.

    It's good that you're testing your Web pages in a Web browser, but validating the HTML and CSS will help you make pages that stand the test of time and new browsers.

  • 相关阅读:
    H50068:html页面清除缓存
    CSS0019: 样式中高度百分比无效时,这样写 height:calc(100%)
    H50067:body 背景颜色 背景图片 background 的 简写属性
    40、在last_update后面新增加一列名字为create_date
    39、使用强制索引查询
    38、针对actor表创建视图actor_name_view
    37、对first_name创建唯一索引uniq_idx_firstname,对last_name创建普通索引idx_lastname
    36、创建一个actor_name表,将actor表中的所有first_name以及last_name导入改表
    35、批量插入如下数据,不使用replace操作
    34、批量插入如下数据
  • 原文地址:https://www.cnblogs.com/limei/p/1812799.html
Copyright © 2011-2022 走看看