Take the 2-minute tour ×

Wondering which is the optimal way of dealing with the css used by a jquery plugin.

Is the best approach to make a css file for the plugin and moving all of that code there? Is there anything more elegant by any chance?

share|improve this question
Keeping your CSS separate is the most elegant solution. –  Jay Blanchard Jan 24 '13 at 17:28
add comment

closed as not constructive by Juhana, Sparky, rds, hjpotter92, Aleksander Blomskøld Jan 24 '13 at 21:08


2 Answers

Keep the CSS for the plugin separate from your main css file. This way you can style the plugin itself accordingly, and if you ever expand and want to use the plugin elsewhere, you'll have the separate files you need rather than rooting through potentially hundreds of lines of CSS.

share|improve this answer
Thank you. I will definitely do this =] –  user1422770 Jan 24 '13 at 17:57
Can you please mark the answer as correct? Thanks! –  adamdehaven Jan 24 '13 at 19:05
add comment

I like the approach of making available a dummy CSS file with commented out sections describing what could be styled. I'd put your default style into the code itself using JQuery. You can check to see whether a master element is styled to determine which to use, the in-code styling or the styling from the stylesheet.

This vastly simplifies the ability both to deploy and try out your plugin without the need to insert references to separate files, while still leaving you the flexibility of having a separate CSS file. This assumes you don't have so much styling to do that performance becomes an issue.

share|improve this answer
Ahh, I will do this as well. Great info, ty =D –  user1422770 Jan 24 '13 at 17:57
add comment