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.
Latest Answers