0

I am looking for a way to automatically prefix all css selectors with a class. For example, css files contains :

.someclass1{...}
.someclass2 button span{...}

And output would look like this :

.prefixclass .someclass1{...}
.prefixclass .someclass2{...}

Looked at LESS and SASS, both do not seem to be doing this :

.prefixclass{ 
   @import 'file.css' 
}

Reason for this is because I want to import user-side css styles in a wysiwyg editor I have made, and it needs the CSS to be applied only to inner editor area, not the whole page.

I would like something that I can input a file to it in command line mode, or even in PHP.

Graben
  • 202
  • 3
  • 8
  • Please do not use multiple language tags that cannot be used together (ie. either pick sass *or* less, not both). Possible duplicates: http://stackoverflow.com/questions/26698230/keep-import-at-the-end-of-css-after-scss-compile and http://stackoverflow.com/questions/7111610/import-regular-css-file-in-scss-file – cimmanon Aug 23 '15 at 15:16

1 Answers1

0

If you are using Sass. Then you could try its nesting.

.prefixclass{
    .someclass1{ }
    .someclass2{ }
}

this will render as follows in your css file.

.prefixclass .someclass1{}
.prefixclass. .someclass2{}

I hope this works for you. If you need to add a prefix using Sass then look into its nesting property. Cheers!!

K.Shrestha
  • 567
  • 3
  • 8
  • Thanks for the answer. I am aware of what sass does. However I would like something that I can input a file to it... cli mode. I guess I could read file in PHP and automatically write a .scss file with the css file content in it and then run the sass preprocessor to generate the final file, but that would probably not be really as fast as it could be with a proper solution for that problem. I guess I did not explain well enough in my question...will correct that. – Graben Aug 23 '15 at 04:56
  • I ended up generating an automatic sass file using this method with PHP, so i'm selecting this as the answer even if its not exactly what I was looking for. Thanks for helping. – Graben Nov 25 '15 at 17:42