DEV Community

Discussion on: Why CSS is Difficult

Collapse
 
alohci profile image
Nicholas Stimpson • Edited

CSS isn't difficult - you're making it difficult. Because you haven't understood the basic principles of HTML and CSS. HTML is a language for indicating the semantics of the content, not their styling. CSS is the language for your styling. Classes are part of HTML and therefore part of the semantics, so your red and pinkBG classes shouldn't ever exist. Your first step is to understand what it is about your HTML content that indicates why it should be red on pink. And why your code content should be navy. And why they are in contradiction. Then you can write selectors not only to bind the content to those styles, but also how to resolve that contradiction.

HTML, Selectors and CSS Declarations each have a rich syntax that work like three corners of a triangle. By limiting your selectors to a single class name, you're discarding one of those corners. Then you're wondering why creating a triangle with only two corners is so hard.