Commenting out stylesheets in HTML documents to su

2020-02-01 16:03发布

I've been reading some fairly old books to learn CSS. I've noticed that most of them recommend that style declarations to be written like this to remain backwards compatible with "older browsers" that don't support CSS:

<style type="text/css"><!--

(style declarations)

--></style>

So my question is, is this still a generally suggested practice (and is it still really used), considering that practically no one these days uses old browsers that can't handle style declarations?

1条回答
▲ chillily
2楼-- · 2020-02-01 16:38

So my question is, is this still a generally suggested practice

Only in cargo cult tutorials.

(and is it still really used)

Yes, but not to any useful effect. They are something that were useful in their day, and now (a decade and a half later) just won't die.

In HTML they are useless. In XHTML they are actively harmful (since script elements don't contain implicit CDATA in XHTML so if the document is parsed as XHTML then they will act as an actual comment and hide the script from the browser).

查看更多
登录 后发表回答