0

At risk of a torrent of downvotes, I will put it all on the line and ask: why aren't selectors allowed inside declarations?

jQuery's nice and all, but it's slower than CSS. Again, I loooooooooooooove jQuery, but a hammer isn't a saw.

Is there a good reason why selectors aren't allowed inside of declarations to make for fast dynamic pages?

Many thanks in advance!

Example

Why can't we do something like this?

.class1 {max-width: #element1.width}
  • Well, for one, it would probably make CSS as slow as JQuery :-). – ScottS Dec 08 '12 at 02:32
  • @ScottS Really? Weird. I thought CSS was only faster because it's compiled. (Although I have no idea how CSS scripts are compiled) –  Dec 08 '12 at 02:33
  • 1
    CSS is not compiled. It's not code that is executed, it's a set of rules, which the browser scans to find the style for each element that is rendered. – Guffa Dec 08 '12 at 02:38
  • @Guffa I'm probably using incorrect terminology, but I saw on one link explaining why CSS animations were faster was because jscript is fully interpreted where CSS is...something else. Maybe I should ask why jscript isn't that...something? –  Dec 08 '12 at 02:40
  • 1
    [Read this answer](http://stackoverflow.com/questions/5797014/why-do-browsers-match-css-selectors-from-right-to-left) to understand selectors better, then you might see why adding complexity as you mention is difficult. What you desire is why they make preprocessors like [LESS](http://lesscss.org/) and [SASS](http://sass-lang.com/) – ScottS Dec 08 '12 at 02:42
  • 1
    @JoeCoderGuy: Javascript is compiled nowadays, so that is not the reason. The difference lies in that Javascript has to manipulate the DOM elements which causes the display engine to recalculate and redraw them, while the CSS animations is built into the display engine itself. – Guffa Dec 08 '12 at 03:04

1 Answers1

2

Expressions was supported in CSS in earlier versions of Internet Explorer.

Support for expressions in CSS was dropped in IE 8, for standards compliance, performance and security reasons.

Ref: http://msdn.microsoft.com/en-us/library/ms537634%28v=VS.85%29.aspx

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • That's pretty sweet! Would you mind expounding on the security risks? Thank-you! –  Dec 08 '12 at 02:37
  • @JoeCoderGuy--such expressions were really just inline javacript; also note Guffa's mention of performance. – ScottS Dec 08 '12 at 02:43
  • 1
    @JoeCoderGuy: As the expressions contains code, they had to be considered for any possible injection attack. I'm sure that the security problem was not so much that the implementation could be insecure, rather that it took a lot of effort to make sure that it didn't contain any serious leaks. Simply too much work for a feature that nearly noone ever used. – Guffa Dec 08 '12 at 02:44
  • @Guffa Then I must be going the wrong way in trying to make totally dynamic AJAX pages that are "perfect" for every screen size then, huh? LOL Many thanks for the knowledge! –  Dec 08 '12 at 02:47