I understand the concept of keeping all presentational elements outside of the markup and putting them into an external .css file.
I want to get a feel for what types of situations you'd justify use of the style attribute vs setting IDs and external Css.
To this point, I've used the style attribute a lot, I usually use it to specify presentation items specific to that element and anything that is for all elements I pull into an external css file but I'd like to reevaluate my position and make the best choice going forward.
Use external CSS for static definitions. Use element ID lookups and the style attribute for things that change at run-time or where you need Javascript to set things up because CSS isn't capable of what you want.
A good example of the latter was zebra-striping in jQuery prior to widespread support for CSS 3 selectors:
$(document).ready = function() {
$("table tr:nth-child(even)").addClass("striped");
});
Today, you can do that in the static CSS, but once upon a time, doing in in Javascript was the best option.
I use external stylesheets and the reasons are below:
I tried to think of reasons of using style attributes, but honestly, I can say I only use it when I am lazy to open up the stylesheet to change something quickly(not too proud of this part, so I try to minimize it)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With