Modular CSS I think is a huge step forward - I totally agree that global scope is killer. As much as people love to hate on CSS-in-JS, I enjoy using styled-components a lot. I've noticed since using it I've been composing CSS instead of inheriting or overriding styles.
CSS: The bad bits and how to avoid them
11–20 of 109 posts
Re: CSS: The bad bits and how to avoid them
#12One of the things I've been doing recently that helps debugging a lot is to group the attributes within a css class into three, separated by a line.
1) Things that control where the item shows up.
2) Things that control the overall appearance of the item, like size and background.
3) Things that control appearance of things within the item, like font color.
Re: CSS: The bad bits and how to avoid them
#13There's nothing wrong with styling on an id. You could put the style right in the HTML tag, or on the page where it's used, but with dynamic pages (and static stylesheets) both options will cost you bandwidth. And they split up your styles into separate places. So putting the style on the id is the right thing to do, and I don't understand why the author is against it. If I need my footer to look a certain way, then…
If you have a choice, use class, then if you need to modify a specific use of the class, use id.
I would still use .footer instead of #footer. Of course you should consider as well.
Re: CSS: The bad bits and how to avoid them
#14The world really doesn't need another "What to Avoid with CSS" list. This list also assumes the use of a CSS pre-processor.
Well, I liked it. I had never heard of BEM before, either, so I'll definitely take a look at that. What gets me about CSS is that, in spite of having used it now for about 20 years, I still don't have an intuitive feel for it. With everything else I work with, I start out with an experimental approach: if I change this, I see this, if I change that, I see this other thing; after usually a few weeks of experimentation…
I have learned to simply accept css for what it is: An unholy legacy kludge we have to live with. Just don't let's speculate on the millions and millions of wasted man-hours over the years.
Re: CSS: The bad bits and how to avoid them
#15Re: CSS: The bad bits and how to avoid them
#16Re: CSS: The bad bits and how to avoid them
#17I'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…
Re: CSS: The bad bits and how to avoid them
#18 [data-controller="user_controller"][data-action="new"] {
.header {
background-color: blue;
}
}
This method keeps you organized and completely removes the biggest problem most people have with CSS.Re: CSS: The bad bits and how to avoid them
#19Isn't that the case with Javascript?
Re: CSS: The bad bits and how to avoid them
#20SASS, BAM, OOCSS, etc are all good practices. You can/will abuse those as well without proper understanding and planning.