Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nested css rules [duplicate]

Tags:

css

Some time ago I saw an example of a css file, where the css rules/selectors where specified in a nested way, e.g. something like this:

div.a {   color: red;   div.b {     font-weight: bold;   } } 

I'm not sure where I saw that (probably in a SO question), or whether it was exactly as shown above.

My questions: Is the above CSS correct/valid? Is it a standard way to specify CSS rules or is this a browser-dependent hack?

like image 951
M4N Avatar asked Sep 15 '10 18:09

M4N


2 Answers

That is not valid standard CSS, but it's an example of nesting class declarations using Sass/SCSS or LESS and I believe other CSS extensions out there, which expand it to something like this (which is valid CSS), before serving it to the browser to use:

div.a {   color: red; }  div.a div.b {   /* Inherits color from div.a */   font-weight: bold; } 
like image 56
BoltClock Avatar answered Sep 22 '22 11:09

BoltClock


What you are probably referring to is LESS.

The example, you gave is not valid CSS, but is valid with LESS. LESS will "compile" the nested CSS and convert it to something which is valid CSS.

like image 32
HoLyVieR Avatar answered Sep 19 '22 11:09

HoLyVieR