TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Where to start with CSS?

26 pointsby xenopticonalmost 8 years ago
Hi HN folks,<p>I am confident writing code in almost all layers of a modern web application now. Node.js&#x2F;JavaScript, SQL, Angular etc., all took me some time to grasp but now are a breeze to write.<p>My pain point is currently CSS. I have a good understanding of advanced selectors and properties, but my final CSS code always end up being a mess. I am constantly overwriting styles, writing classes that can&#x27;t be reused or composed in more than one element and using way more !important rules than I probably should.<p>Where do I start on the path to write clean, reusable and maintainable CSS?

7 comments

dyejealmost 8 years ago
I attended both of these talks and found them very enlightening. My team hired a CSS expert to do some part time implementation work and evaluate our practices. I was pleasantly surprised when his analysis of our codebase was very positive.<p>To me, the key is to think of everything in your app as a component. You should be able to drop the component into more or less any context and it should &#x27;just work&#x27;. Following the ideas in the videos will help you accomplish that on the CSS side.<p>CSS is a Mess - Jonathan Snooks (ex-Lead Frontend Developer Shopify) <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=fAcW-wOFYjw" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=fAcW-wOFYjw</a><p>CSS for Engineers - Keith J Grant (NYSE Engineer, author of CSS in Depth) <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=J-9Tn6AetYA" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=J-9Tn6AetYA</a>
codegeekalmost 8 years ago
I really like <a href="http:&#x2F;&#x2F;cssreference.io" rel="nofollow">http:&#x2F;&#x2F;cssreference.io</a><p>They have a visual guide which shows you what it looks like along with code on side.
ninjaofawesomealmost 8 years ago
You may want to look into Sass (SCSS). It makes your code reusable and extendable via variables, mixins, loops, if&#x2F;else statements- its quite robust.<p>Another suggestion, such as SMACSS is BEM (my personal favorite), as it flattens out your styling to prevent over specificity and makes everything clean and neat. (Check it out here: <a href="http:&#x2F;&#x2F;getbem.com&#x2F;" rel="nofollow">http:&#x2F;&#x2F;getbem.com&#x2F;</a>)<p>Ultimately though, what I&#x27;ve found reduces messes is to think of the end product before beginning. If you have the luxury of starting with a fresh codebase, think of the end product and its styling before starting- much like you would with any other set of features in any other language.<p>If you&#x27;re walking in to legacy code, try to avoid the &quot;one-offs&quot;. Sure, they solve the problem now, but its making a mess for future you to clean up as well as being a potential code smell. Leave your code a little better than when you came in and you&#x27;ll be thanking yourself later.<p>Good luck!
cag_iialmost 8 years ago
I think the SMACSS doc is worth a read:<p><a href="https:&#x2F;&#x2F;smacss.com&#x2F;book&#x2F;" rel="nofollow">https:&#x2F;&#x2F;smacss.com&#x2F;book&#x2F;</a>
评论 #15068523 未加载
LarryMade2almost 8 years ago
One trick I just learned is you can combine classes - when setting class in a property put in multiple classes by separating the names with a space. i.e. &lt;div class=&quot;manny moe jack&quot;&gt;web stuff&lt;&#x2F;div&gt; Now you can pull apart the unique bits from the reusable ones.<p>Other than that a lot of my CSS cleanup happens in refactoring the layout
vanderreeahalmost 8 years ago
<a href="https:&#x2F;&#x2F;css-tricks.com" rel="nofollow">https:&#x2F;&#x2F;css-tricks.com</a>
maxharrisalmost 8 years ago
npm.im&#x2F;styled-components