How does CSS work?

398 viewsOtherTechnology

I’m a programmer by trade. I use CSS just about every day, but I’d be lying if I said I understood how it works under the hood. What exactly does CSS do behind the scenes when I pass the parameters? How does browser support play a role in all of it?

In: Technology

4 Answers

Anonymous 0 Comments

It’s really not magic. The browser is written to categorize visual elements in different buckets like type, class, and id. The CSS text gives visual properties to types, classes, or ids. When the browser wants to display something, it looks in the thing’s metadata to find its type, class, and id. Then it finds the CSS rules for those.

Type is more general, class is middling, id is most specific. When the browser applies styles, it applies the most general first, then overwrites with any styles specified in the next less general, and so forth until finally overwriting with any specified in the most specific. CSS is “Cascading Style Sheet”. This is the “cascading” part, where the more specific overrides the more general.

And then it shows the object based on that cobbled together, cascade-overridden set of styles.

I guess it’s all magic. But it’s just average run of the mill magic.

You are viewing 1 out of 4 answers, click here to view all answers.