I feel there is an aspect that has not been addressed here: the difference between manually edited, edited HTML snippets and generated HTML snippets.
For human editing, it is probably better and easier to maintain styles in a file.
but
As soon as you start generating HTML elements using scripts on the server side or with some kind of JavaScript, be sure to create all the styles necessary for the basic functionality!
For example, you wrote some kind of JavaScript library that generates tooltips. Now you enter DIVs on your page, which will require some styles. For example, position: absolute and, initially, display:none . You may be tempted to give these elements a .popup class and require that this class have the correct definitions in some CSS file. In the end, styles should be specified in the CSS file, right?
You will make your JavaScript library very annoying for reuse, because you can no longer just copy and call a single .js file and do with it. Instead, you will have to copy the .js file, but you also need to make sure that all the styles required by the script are defined in your CSS file, and you need to go look for them and make sure their names do not indicate a conflict with the classes that you are already there.
For maximum ease of use, just go and set the necessary styles directly to the element when creating it. For styles that are exclusively for aesthetic purposes, such as background-color , font-size , etc., you can still attach a class to give your script consumer a simple way to change the appearance of your script elements, but don't require this !
rix0rrr
source share