The CSS for dev.to is fairly wild-west right now. It's mostly scaled by way of isolating parts, meaning more copying and pasting and relying on SCSS nesting, less re-usability and few true rules.
I'm wondering if there are any CSS methodologies or strict rule sets you've used that you like. I'm familiar with BEM and would lean towards that from what I know, but I'm looking for some input to bring to the team.
Latest comments (38)
Sass with scss. BEM. That's it.
As a previous Chemistry nerd haha I am truly a fan of Atomic Design for UI in General :)
I've been learning styled-components after listening Wes Bos' Syntax podcast on the topic and a friend suggesting a look-see at them. So far, I'm really liking it. But I'm very much one for "keep everything together and easy to find", which is a selling point: the styles for the component are right there if you need to refactor/remove something.
Or, go the other route and try vanilla-css.com
You should take the CSS-in-JS approach and just use random alphanumeric strings to represent styled elements/components.
One of the easier naming conventions I've found is rscss.
I love Tachyons (CSS library). It basically means that you almost never have to write custom CSS. Once you've started to get used to it it's so much faster. Not only that but it solves the CSS scoping issue in plain CSS which means it doesn't matter which framework you use. It's based on a design system so I makes it easy to make everything feel very cohesive. It's also trivial to make responsive websites with it. I've used it for many if my personal and work projects and have nothing but good things to say about it.
Sorry, just a bit of a fan.
We like to follow the Trello CSS guide as we find that helps maintain some discipline on our larger systems.
I would look at the underlying stuff -- make the pattern library first then implement the pattern library with whatever makes sense for size and scope.
I like a combination of custom styles with less.js and styled components.
ITCSS at it's finest ! medium.com/dev-notes/just-do-itcss...
I really like cssguidelin.es/ and the 7-1 file structure from sass-guidelin.es/ or some variation of it like smaccs. CSS guidelines is a pretty robust read but I love that it also drops tidbits of things I didn’t know just by explaining why some ‘rules’ exist at all. Both of these are from people I’ve followed and trusted for ages now so I may have a bit of selection bias haha
I've seen a post about a css pyramid coding rules.
It was 9 css files, applied one by one, from the most general to the most specific. I try to find the article ..
@ben
Don't go for hype-driven development!
Use stable architecture! Stay clear of frameworks, preprocessors and build steps. CSS is all you need! Base it for example on Herry's BEMIT and ITCSS. In addition, use very small and simple rules, meaning mainly one class you select (without nesting).
BEMIT is a naming convention, which makes sure that you can get a lot of info from the class name alone: How many elements are affected? Which role does it play? Where on the site can I find it? For example
c-menu__logo--small@mq-mobile
is a class name, which affects one element, located in the menu, which is a logo and makes the standard representation smaller in size. Additionally, it will only affect the mobile media-query.ITCSS is basically establishing layers of specificity (ranging from generic to specific), which makes sure you override rules in a sane manner. Harry uses the layers Settings, Tools, Generic, Elements, Objects, Components, Utilities in that order, but you can of course define your own!
On top of that, factor-in theming from the start. I already wrote an explanation, so I'll just copy that here:
t--light
t-
(theme) CSS class. For examplet-menu__item--active
>>> Full Example
Using the above techniques allows you to very easily
Yeah, I like this approach as well. I use a modified/simpler system of BEM/ITCSS, namely:
Structured like so:
Couldn't agree more! I think my favourite ways to write css are based on BEM(IT) and SMACSS. Thanks for t he great comment.
Hehe, you don't have to tell me about avoiding the hype. We probably have the least hypey approach I can think of. 😄
Thanks a lot for the tips. Will definitely take into consideration.
When full stack developers, a.k.a. Devs who doesn’t care much about style but need to keep the site in a decent shape, where in charge we followed the Trello guide gist.github.com/bobbygrace/9e961e8...
Now we have front end devs using Atomic design, but we keep the
js-
rule to id classes that are not use for styling but for JavaScript.I'm a huge fan of SCSS + BEM, with the component-driven architecture of BEM complementing the component-driven architecture of React. I usually give each component its own small stylesheet and
@include
it in a main stylesheet. I have found that this gives me the most flexibility, readability, and re-usability of anything I've seen.I've had great results with a similar setup, (also a React app), although with two differences:
@include
in a core stylesheet, I tend toimport
the stylesheet directly in the component's JS source, using webpack loaders to handle this. This allows for slightly better build performance when developing, especially when using Storybook or similar, as well as not having a huge list of stylesheet imports in one place.One great thing baked into Angular: CSS scopes! I am a fan of Atomic Design :)