HTML Comments inside Opening Tag of the Element

前端 未结 5 1335
予麋鹿
予麋鹿 2020-12-16 09:15

When I try this

 to mark comments inside a tag. However there are workarounds for the main use cases.

To add a comment within an HTML tag

You can just make up an attribute that you use just to comment to yourself. For example:

...

The major downside is that the comments will not be stripped out during minifying, so:

  • it will take up space in your final HTML document served to the user
  • if the user clicks View source they will be able to read your comments

To temporarily disable an attribute

Just rename the attribute with a prefix that you know to indicate temporary disabling. For example, to disable an attribute called option:

...

becomes

...

Obviously don't do this if there is actually a valid attribute called disabled-option.

To temporarily disable a class or style

Since there is no error message if you use a class or style that doesn't exist, you can do this to disable a class or style:

For example, to disable a class called tall while preserving a class called highlighted:

...

becomes

...

Similarly, to disable the color style while preserving the font-weight style:

...

becomes

...

Again, remember that these won't be stripped out during minifying so they will take up space in the file the end user receives, and will be viewable with View source.

提交回复
热议问题