Is there a NOOP rule that can be used in a css file?

I am working on some reorganization of legacy code to move styles to a stylesheet file from html. Our build process runs CSS style files using the YUI minifier compressor. Which, in its effectiveness, removes empty .selector { } styles, see - YuiDoc There is no empty declaration section .

The problem arises when in some places the code finds and modifies the rules of the style sheet, but cannot find the rules that have been reduced / stripped. Is there a noop rule that they will not render any rendering but keep the effective empty rule in the stylesheet?

+4
source share
1 answer

According to W3C CSS2 Specification

In CSS, identifiers can begin with '-' (dash) or '_' (underscore). Keywords and property names beginning with - 'or' _ are reserved for vendor extensions

Thus, you can create your own property, for example, -custom-noop: noop; without checking the complaint. However, you may have problems with older browsers, ignoring other rules in the block if you use this.

Edit: Perhaps you are also lucky with this syntax:

 .someclass{ /*! Keep Me */ } 

Comments like this are stored after compression, so it can work in order to leave a comment in the block. Please note that after compression ! splits, so you will need to add it back every time you compress it.

+4
source

Source: https://habr.com/ru/post/1381823/


All Articles