What's the point of valid CSS/HTML?

2019-01-06 17:50发布

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 browsers and Firefox. I don't care if they don't show up on Internet Explorer. But I keep my HTTP requests down by not including images instead.

Are there are advantages to valid code? In SEO or otherwise?

17条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-06 18:30

I'll answer by an analogy. What you are saying is like saying I like building my cars with square tires, it might not be valid everywhere, but it works for me.

If you do not make a product that can be available by a maximum of people, how do you expect your product to be known and used by a maximum of people. By ignoring people that are using IE (which is still the majority of people, by the way) your shooting yourself in the foot. You need to create something that can be used by a vast majority of people while trying to follow the standards for those browsers that do follow them.

查看更多
爷、活的狠高调
3楼-- · 2019-01-06 18:31

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.

查看更多
三岁会撩人
4楼-- · 2019-01-06 18:32

"Valid" code isn't so much important as "semantic" code. If there are font tags all over the place and list tags that don't close, it'll be both difficult to maintain and hard to parse with strict and proper xml parsing engines.

查看更多
兄弟一词,经得起流年.
5楼-- · 2019-01-06 18:34

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).

查看更多
欢心
6楼-- · 2019-01-06 18:38

You can't test in browsers that haven't been released yet!

Browsers tend to become more standards compliant over time. If you write standards-compliant webpages, they're more likely to still work in the next version of all existing browsers.

查看更多
做个烂人
7楼-- · 2019-01-06 18:39

The standard is only a suggestion, as you can write your own DTD and decide shadows are part of that standard and then your page would validate just fine.
The existing standards are work in process which are being affected by many parameters, not all 100% professional/technical.
The main reason to use standards is it is said will cause your page to render the most similarly between browsers (at least those browsers who support standards :-) )

查看更多
登录 后发表回答