开发者

What kind of language is CSS?

开发者 https://www.devze.com 2022-12-27 16:24 出处:网络
What kind of language is CSS? My first inclination was to c开发者_运维百科all it a markup language... but it doesn\'t really fit the mold:

What kind of language is CSS?

My first inclination was to c开发者_运维百科all it a markup language... but it doesn't really fit the mold:

A markup language is a system for annotating a text in a way which is syntactically distinguishable from that text. -wikipedia

CSS uses various selectors to apply properties to elements within HTML, a markup language


I would say it is a domain-specific declarative language.


Syntactically, CSS is a mix of two languages: the language of selectors, which is a pattern-matching one, like regexps or xpath, and the language of properties, which can be classified as "procedural-declarative", because properties are essentially assignment operators. At a subjective level, css clearly qualifies as ugly mess, like pretty much every other fruit of collective efforts on the field of language design ("a camel is a horse designed by committee").


CSS is not really a language, per se; it is more of a syntax for describing configuration directives.

In fact, it is neither of these things; CSS is a description of a number of tokens and their visual meanings; .css files contain these tokens structured in manner allowing a computer to parse them. CSS declarations can take the form of name="value" declarations in SVG documents; and the .css file structure could just as easily be employed to, say, contain unit descriptions in a particularly absurd iteration of FreeCiv.

Wikipedias definition of it as a Style sheet language seems like a bit of a forced definition of a generalization of a singularly existing phenomenon; and it should be clear that it is not in any way a markup language, as it doesn't actually, by itself, mark anything up.


CSS is most definitely a language:

Wikipedia refers to css as a 'style sheet language'

http://en.wikipedia.org/wiki/Style_sheet_language

Also from W3C who developed CSS: (comparing xsl and css)

The unique features are that CSS can be used to style HTML & XML documents. XSL, on the other hand, is able to transform documents. For example, XSL can be used to transform XML data into HTML/CSS documents on the Web server. This way, the two languages complement each other and can be used together.

Both languages can be used to style XML documents.

As you can see from the second sentence W3C refers to CSS as a language.

http://www.w3.org/Style/

And the next quote again from the same article:

The fact that W3C has developed XSL in addition to CSS has caused some confusion. Why develop a second style sheet language when implementers haven't even finished the first one? The answer can be found in the table below:

                            CSS     XSL
Can be used with HTML?      yes      no 
Can be used with XML?       yes     yes
Transformation language?     no     yes
Syntax                      CSS     XML


CSS has a well-defined grammar, thus it is a language, and if you had to choose between CSS being declarative or imperative, then it would be declarative, as the results of its operation are determined by the program actually interpreting and processing the CSS.

However, you can't build anything useful with CSS alone; it needs a document to operate on, and all the CSS does is provide supplemental information for the document; effectively, then, the CCS is a part of the document it operates on.

The problem with CSS is that is it used as part of the HTML to DOM generation process; therefore CSS behaves similar to "messy" global variables, and as a result, developers have to deal with the plethora of nasty side effects CSS brings along with it.

Hopefully, Håkon Wium Lie, the inventor of CSS, and a major player at the W3C will one day come to realize that CSS was and is a mistake from the beginning until today and the wrong path to take to achieve a separation of semantic markup and presentation.

Today, CCS is gaining imperative features with @media queries, and targeting with @operators, such as @screen and @print. But none of the new features will correct the fundamentals flaws of CSS: the god-awful globals, and the notorious unreasonable use of side-effects with its element selectors.

Unfortunately, the study of CSS as a language is more complex than the study of real programming languages, as examples of how to use it are more anecdotal than practical, hence the need for comprehensive CSS frameworks like Bootstrap and others to get your job done.

0

精彩评论

暂无评论...
验证码 换一张
取 消