HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Is there a theoretical foundation behind CSS?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
cssfoundationtheoreticalbehindthere

Problem

You know how programming languages can be based on Lambda Calculus or the Turing Machine and SQL is based on relational algebra. Is there any such thing for CSS or any foundation that could be used for styling languages in general if we were to design a new language from scratch?

Styling and layout in general is something I'd expect to be possible to formalize mathematically, at least the layout and positioning part of it.

Solution

I don't think there is a deeper foundation, as CSS is just a lookup table of key value pairs declared under certain rules. It then gets interpreted by the browsers' graphical renderer. From a linguistics perspective, I'd see CSS syntax as the following: Map>, where Rule is its own querying or pattern matching statement.

I agree on that CSS seems like a mess sometimes. Especially when you have to re-use some of the rules, key-value pairs multiple times. For those cases, I recommend transpilers like Sass. It allows you to declare rules in a less verbose way, and allows you to encapsulate certain key-value pairs to be able to reuse later.

Context

StackExchange Computer Science Q#160704, answer score: 5

Revisions (0)

No revisions yet.