Is it bad practice to comment out single lines of CSS with //?

前端 未结 11 1737
梦如初夏
梦如初夏 2020-12-01 02:45

I have recently started using // to \"comment\" out single lines of CSS code. I understand that I am not actually commenting out the line; I am just breaking it

11条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 03:24

    As others have said, using a double slash is not standards compliant, but if you really want to use it AND want to be standards compliant AND you have gcc installed, you can run your CSS through cpp -P to strip out all double slash and /* ... */ comments from the CSS. As a bonus, you can use macros, includes and conditionals, and comments don't get downloaded by the browser (minor performance boost).

    The only major problem is using standalone id tags (i.e., #para { ... }) where cpp barfs. Solution there is double the # (to ##) and pass the output through sed, like this:

    cpp -P site.cssin | sed -e 's/^##/#/' >site.css
    

    I'm sure there are better CSS-oriented preprocessors, but this worked for me.

提交回复
热议问题