What's the point of valid CSS/HTML?

前端 未结 17 1928
梦如初夏
梦如初夏 2020-11-30 06:40

If I\'ve tested my pages in most major browsers, why would I need to maintain a validated code? I want to use box-shadows and corner radius if they\'re supported in WebKit b

相关标签:
17条回答
  • 2020-11-30 07:25

    I'd say valid (X)HTML is a must, since this defines how your content can be accessed. Badly formed HTML can stop your content from being "read" by not only humans but also machines (think search-engines, spiders etc). Imagine if a bank held your account details in a badly formed XML file and then sent that XML to another bank as part of a transaction - there is a danger that the bank would mis-read the amounts due to the different way it tried to interpret the sums.

    Valid CSS is slightly different as it is purely stylistic and effects presentation, not content. Therefore it is not as essential to keep it valid, so long as you don't mind different user agents presenting your content in different ways.

    0 讨论(0)
  • 2020-11-30 07:27

    As long as it works in the browsers you care about then it doesn't matter. In theory your maintenance costs might be lower with validated code.

    You have to determine what the success criteria for your project is. If your program does what your client needs then just because you code is "valid" doesn't make it more magical in and of itself.

    0 讨论(0)
  • 2020-11-30 07:32

    This is no different than asking if there are advantages to writing syntactically valid C code: Such a program need not do the right thing™ but doing the right thing without valid code will be harder.

    Related discussion on SO: Do you validate your websites?

    0 讨论(0)
  • 2020-11-30 07:33

    Here is another point... If you're writing a SharePoint web part, you can just about the worst possible, messy, cruffy and dodgy HTML you could possibly imagine, and your web part would feel right at home in SharePoint.

    It actually amuses me seeing purists try code valid HTML strict for a MOSS plugin when the entire framework spits out garbage.

    Its no wonder you can't find anything on a corporate intranet....

    0 讨论(0)
  • 2020-11-30 07:33

    The best reason to follow a standard is to reduce fragmentation of the standard, which leads to instability.

    If everyone breaks the standard in exactly the same way and it's well thought-out, then that's not as much of a problem. Over time the standard will evolve to match what has become the common practice. Look at how modern HTML has moved on from SGML comment rules, tag minimisation, etc, and how <!DOCTYPE html> is enough to trigger standards mode. These are all against the standards but are common practice, and now the new standards (HTML5) are even evolving to support these.

    If everyone breaks the standard in a different way, through general sloppiness or through wanting to invent their own 'hack', then the standard does not evolve, but it fragments. Browsers have a harder time supporting every different direction that people have gone in to hack something so that it looks right (or just through sloppy mistakes). They've done a good job so far of remaining backwards-compatible, but it's been at the cost of a huge increase in parser complexity. Sooner or later, however, less popular or more obscure hacks or errors stop being supported, because they were just stupid ideas to begin with (various CSS selector hacks come to mind) or they were just too far out of left-field (the <layer> element, and so on).

    0 讨论(0)
提交回复
热议问题