I think maybe he just enjoys being controversial. I have no idea how anyone could really encourage multiple developers to work on a project with a single CSS file - it seems practically almost impossible to me.
This guys understands CSS, and if you actually understand CSS you dont need tools like SASS, and you dont need rigid structures like BEM.
The most beautiful (and seemingly ignored) aspect of CSS is that specificty cascade. Everybody seems to be trying to isolate their CSS into modules so they dont conflict instead of using the CSS together in harmony.
After writing thousands upon thousands upon thousands of lines of CSS here are my quick opinions:
- 1 global CSS files should take care of 95% of the styling, and if a specific views needs to override that global style, give it a teenty tiny bit of CSS
- SASS is cool, but largely unnecessary, and so I believe that 80% of the time people use it it just creates more work (learning curve, project requirements, compliation step) than it saves. Again, I write CSS for a living and I have never found a place where SASS sould have saved me work if you actually know how to write CSS.
- Nesting is awful, thats not how CSS works. I could abuse indents and arbitrarily block my code in JavaScript and if I did that everybody would assume I was an amateur who didnt know what I was doing. When I see nested CSS I go on high alert for bugs because it is clear the author doesnt understand CSS
- while IDs and classes can be useful, So many frameworks now work in a way that they write all of the styles you might nedd in advance and then you 'tag' which elements get which styles ising classes. This is literally no better than inline styles, and is an abuse of HTML in an attempt to not have to write a small amount of CSS. If your markup is CLEAN and simplethen styling it with CSS is also very straightforward. I havent read the authors piece but in the past year I have noticed a drastic reduction in my own use of classes and other identifiers in HTML as my understanding of more advanced CSS selectors has increased.
CSS is a beautiful, POWERFUL language, and I would recommend everybody to do a few things:
- stop using CSS you didnt author
- write your CSS by hand (no SASS, STYLUS, LESS)
- Only ever copy-paste code youve written, if youre bringing external CSS into your codebase, retype what you need from it.
I know those sound like youre going to be sitting there forever typing in thousands of lines of CSS, but operating that way VERY QUICKLY forces you to gain skill at discerning what is actually required or not.
Whenever I do responsive consulting I feel like most sites are 5x overbuilt in the HTML, which means that your CSS is many many times longer than it needs to be. The biggest bottleneck to CSS simplicity is poorly thought out HTML markup.
(I'm also not sure what is meant by "nesting": combining selectors like this "div p" or "div > p"? Or is it something specific to SASS?)
One thing that really helps me read code is using a syntax-highlighting editor with a decent colour theme. You don't need auto suggesting, automatic tag closing, or anything. Every keystroke you press on the keyboard should map to one character being added or removed from your document.
Soon you'll find a formatting style that helps you quickly scan and read. For quickly skimming CSS it's best if it's all on one level. Selectors can be long, so starting them at arbitrary indents makes it a mess.
What they mean by nesting would be grouping 'blocks' of CSS together by indenting them. This might be one way somebody would nest button hover state under a CSS rule for a button:
button {
background: darkgreen;
}
button:hover {
background: green;
}
This is a super clean example, but in a big CSS file it can get pretty messy pretty quickly.That said, I'm a little surprised you see no value at all in CSS preprocessors; having spent over a decade writing CSS by hand (from the CSS 1 days), it was a moment of sheer joy when I started using Sass - probably more than five years ago now - and discovered variables and mixins could be used with CSS (and to a lesser extent nesting - though it's immediately obvious to anyone who looks at the actual output or thinks for a moment about how this works that it isn't a great idea to overuse it). I would find it very hard to go back to writing raw CSS.
If you're working on a team of developers all contributing CSS to a project, do you find that one CSS file is actually manageable? Do you not get merge conflicts? Does it require vast discipline?
100% agree with you about the quality of actual markup in 2015. It's miserable.
I find value in CSS preprocessors in a few limited cases:
- auto-prefixing for added browser support. Especially with CSS animations this is one place where automatically generating the browser-specific CSS can be a time-saver
- for expressing design patterns that may be present in CSS in a more succinct, clear way as a way of teaching or demonstrating a pattern to others
- as a master copy to generate CSS that will be edited and maintained by hand. Suppose I built custom WordPress themes for a client I could have a SASS reset and base set of styles and then for each new project generate my CSS file and go from there
> If you're working on a team of developers all contributing CSS to a project, do you find that one CSS file is actually manageable?
I am more of a responsive specialist so I'm usually brought into existing projects where other programmers and designers have managed to get the code into a knot they can't untangle, so I don't change the existing codebase unnecessarily just to condense things, but for the project I author I will usually deliver a global CSS file that includes all layout, typography, form, button, and responsive styles, and then it's common to include an additional stylesheet for each plugin you might be using. If you have a responsive table plugin then it likely has one JS and one CSS file that need to be included and I would link them in as external files instead of inlining them in my global CSS. We then work with it as a team from there and it's been working well for us keeping things more simple.
> Do you not get merge conflicts?
Working this cleaner way has greatly reduced the merge conflicts we used to get when we were fully working within the 'Bootstrap' mindset and using 'classy HTML' and frameworks. Now we write clean markup, we pass over it with JS and enhance it how we need and use CSS and a CSS polyfill that adds element-based responsive queries as well as scoped CSS and the code is pretty terse. Not much there to conflict with :)
> Does it require vast discipline?
Yes! But I'm surprised at how little HTML, CSS, and JS is actually required to build some really cool stuff. On thursday I was experimenting with the web audio API and I made this teeny tiny HTML5 app that I bookmarked on my phone and tablets and was able to play with over the weekend. It only took a few lines of HTML, CSS, and JS to make a fully fuctioning web app - why would I write more than I need to to do the same thing? I can iterate pretty fast when I know how little code is actually required.
http://staticresource.com/synth.html
And that obfuscated blob at the bottom is nothing special, it gets unpacked to become a set of instructions to build the favicon and app icon using a canvas tag and attach it to the document. I encoded it using another teeny tiny HTML5 app I built http://staticresource.com/encode.html
You can view the source code of these by using another tiny tool I built that loads the requested page's source code and displays that instead. This way you can 'view source' even when using your phone or tablet. http://staticresource.com/inspect?/synth.html
If I was trying to use React or Node with Bootstrap and jQuery for every project I tried to build it would be a headache trying to build all these tiny little tools and apps. No wonder people need all this crazy front-end tooling. If you know HTML, CSS, JS, and learn the command line for manipulating files and batch operations, as well as for ow to automate routine tasks you do that's pretty much all you need in your toolbelt.
Whenever I work with teams I adapt to fit their pre-existing style decisions and tools because that's part of what I'm being contracted to do, and I desire to provide the most value while providing the least amount of friction.
Edit: and the significance of being able to build HTML apps so tiny is that you can write them on the devices you use them on! These are entire apps that you can sit down and write in Vim without it being awkward. I wrote this little page to learn how to detect multitouch on my ipad one morning on vacation. It's so simple: http://staticresource.com/touches.html I wouldn't have an easy way to write and test code using libraries on my tablet, but I could write this and test it and I learned a lot. This is huge considering Amazon just relased a decent tablet for $50, we can finally use these devices for creative work building HTML5 apps and stuff is simple enough now that just HTML, CSS, and JS is needed to build things.