Not only is that more rules to satisfy that outdated csslint it also complicates the css and makes it more unreadable! CSS isn’t just about smaller stylesheets it’s about readability, maintainability and common sense. (undoing styles is also considered bad practice)
If it makes the page easier to read and more understandable then repeating the odd image declaration is not a problem.
Read this to find out what you shouldn’t be doing.
However the question is why you should care so much about this CSS when you have ignored everyone’s comments about the nonsensical html you are using? If after everyone has spent considerable time answering your questions you go and do the very thing you were advised not to do is almost beyond belief.
I don’t understand the purpose of the code in this topic. Don’t modern browsers avoid downloading duplicate copies of images? (“modern” as in later than IE6 - which died before I was born )
It seems the OP, after persistently evading best practices recommended here, is now taking advice from a “linter”.
Reading the explanation in the link it appears the reason to avoid duplicate backgrounds is to save repetition in the css, not server requests. While I understand this point entirely, the opposite argument could be that you may apply the same logic to absolutely any css property that is used more than once in a style sheet. Do that for everything and you quickly end up with a million and one utility classes and every html element holding at least half a dozen different ones. The result being a more cryptic version of in-lining (not unlike Bloatstrap )
In the end it’s up to the developer’s judgement to determine where to draw the line with this kind of reusable/utility class set up. There will always be a tipping point where attempts to slim things actually create bloat and less maintainable code.
One reason I don’t always agree with these linters, there isn’t always a one best way that suits every scenario. The best approach should be decided on an individual basis.
Thank you for that explanation, Sam. I did indeed miss the point of the linter minimizing the background image calls in CSS rather than server calls. I fully agree with you regarding the discretionary arrangement of rules in CSS. I try to write reasonably efficient CSS and to arrange and comment it so I will be able to read and understand it a year after writing it. A couple of recent experiences reminded me that that practice is more than just a good idea .
Using a linter is also a way of enforcing certain standards across a team so that code is uniform and doesn’t look like it has been written by several different people. Large web sites can quickly become messy if the whole team doesn’t stick to certain sets of guidelines to produce uniformity. Despite the animosity for frameworks in this community they do much the same. Using bootstrap or foundation leaves high level architectural decisions to others and allows a team to focus on building an end product. Without those frameworks or the experience to make smart architectural decisions on team projects can quickly become very messy. I’ve never worked alone always on team on larger projects with continued maintainence. In those environments certain trade offs are required to keep things smoothly running f on an operational perspective. Much of that has to do with standardization across the entire team for better or worse. Also devs come and go so it’s important to implentations constructs like frameworks which make it easier for the next person to get up to speed quickly so long as a person with that skill set replaces the other.
Just because that’s the html you see in the code, doesn’t mean that’s the one I’m using.
When I make changes to one version, I make the changes in the other versions also.
I could have removed the html, and left it like this though, so you wouldn’t have gotten the wrong impression about what code I was using. Which probably would’ve been better.
But the question remains as to why you are keeping and working on what you know to be bad code.
From the perspective of those who have put time and effort into teaching you best practice and helping you create good code, it appears perverse and contemptuous when you revert to posting your previous bad code.
If you choose to work on it for your own reasons, so be it, but it is not reasonable to ask others to go over and over the same issues in numerous different versions.
I strongly suggest you post only the good versions of your code when asking for further assistance, if you want to avoid alienating those who might help you.