CSS: The bad bits and how to avoid them
41–50 of 109 posts
Re: CSS: The bad bits and how to avoid them
#42Never understood why people prefer verbose and repetitive BEM classes over custom properties and appropriate CSS selectors. becomes This solves for specificity, and uses built-in CSS features instead of a "manual" workaround.
Re: CSS: The bad bits and how to avoid them
#43I'm a huge fan of 1 & 2, so I end up using CSS with only class names. This helped me deliver maintainable and reliable stylesheets that other devs like. Most importantly using only class names you will gain : 1. Your HTML / CSS is easier to maintain. 2. Is faster to develop. 3. Is faster to refactor. 4. Is more portable. 5. Is faster for the browser. I even wrote a blog post about it [1]. http://www.drinchev.com/blog…
But your HTML is uglier.
Re: CSS: The bad bits and how to avoid them
#44In my opinion, most CSS bad bits are a byproduct of bad use, not a problem of the language(?) itself. SASS, BAM, OOCSS, etc are all good practices. You can/will abuse those as well without proper understanding and planning.
> In my opinion, most CSS bad bits are a byproduct of bad use, not a problem of the language(?) itself. I've seen far too many bad languages come and go to believe that anymore. People used to say that about PHP and VB6 too. PHP eventually stopped with the "only bad programmers use me badly" and grew up, and VB6 died. A win in both cases. CSS could be far better; and bad practices won't disappear until doing it the r…
Re: CSS: The bad bits and how to avoid them
#45EDIT: Perhaps by implementing the whole browser in WASM? Would that even make sense?
Re: CSS: The bad bits and how to avoid them
#46Re: CSS: The bad bits and how to avoid them
#47Never understood why people prefer verbose and repetitive BEM classes over custom properties and appropriate CSS selectors. becomes This solves for specificity, and uses built-in CSS features instead of a "manual" workaround.
Because "my-block" is not a valid attribute for div. You are breaking one language in your attempt to fix your problem in another language.
It's still shorter, more readable and avoids repetitions. The difference becomes even more pronounced as the complexity of your styling goes up.Re: CSS: The bad bits and how to avoid them
#48Earlier quoted context omitted.
Because "my-block" is not a valid attribute for div. You are breaking one language in your attempt to fix your problem in another language.
This argument doesn't stop a myriad of widely used JavaScript frameworks that rely on custom attributes. Besides, if you really care about validity, you can use It's still shorter, more readable and avoids repetitions. The difference becomes even more pronounced as the complexity of your styling goes up.
To be fair, I don't know the latest performance figures on attribute selection.
Re: CSS: The bad bits and how to avoid them
#49Earlier quoted context omitted.
I think the author probably agrees with you. What you pointed out is the exception to the rule though. The percentage of things on a page that are "singletons" is very small compared to reusable widgets. If you don't have much resuable stuff on your site, that's a code smell in itself
> If you don't have much resuable stuff on your site, that's a code smell in itself It can be reusable and yet unique on each page. And those should get id's, and are not rare at all. > The percentage of things on a page that are "singletons" is very small compared to reusable widgets. That isn't necessarily true. Obviously there are different types of pages, but a typical page will have a number of elements on it th…
Re: CSS: The bad bits and how to avoid them
#50Instead of quitting front-end dev, you might also consider using https://www.styled-components.com/
Styled-components solves all of the issues the author highlights in his writeup.
Bonus: styled-components works both on web and on React Native! So you don't have to throw out all your stuff to participate in the post-browser future...