I have been waiting for this moment for a long time, no honestly, somewhere in the subcortex, I really, really wanted such a thing so that it was convenient to write in CSS without rewriting similar styles twice, without looking for the necessary sections in my own code, in general I wanted to it was easy and simple to work, something I delayed ... And so meet xCSS - a php-class for working with dynamic CSS. vars { $path_ = /images/icons; $basicColor_ = #ffcc00; $headerFonts_ = Arial, Tahoma, Verdana } #downloads { list-style-image: url('$path_/folder.png'); border-left: $basicColor_; } h1 { color: $basicColor_; } $newColor = #ffcc00 , and $newColorBg not declared, but is used in the code, as a result of which $newColorBg will remain #ffcc00Bg . li.poduct { a { color: $basicColor; } .price { color: $priceColor; font-size: 2em; } .buy { background-color: $attentionColor; } // … .. .. } li.product a { color: $basicColor; } li.product .price { color: $priceColor; font-size: 2em; } li.product .buy { background-color: $attentionColor; } // … .. .. .product { self { min-width: 200px; min-height: 300px; } h1 { padding-bottom: 1em; color: $headersLight; } } .bestSeller extends .product { self { background-color: $productBestBg_; } h1 { color: $productBest_; } } .new extends .product { self { background-color: $productNewBg_; background-image: url($path/new_bg.png); } h1 { color: $productNew_; font-size: 1.2em; padding-bottom: 1.8em; } } In russeltat we get a set of all the necessary rules: .new, .bestSeller, .product { min-width: 200px; min-height: 300px; } .new h1, .bestSeller h1, .product h1 { padding-bottom: 1em; color: $headersLight; } .new h1 { color: #00ffcc; font-size: 1.2em; padding-bottom: 1.8em; } .new { background-color: #0000cc; background-image: url(/storage/images/new_bg.png); } .bestSeller { background-color: #ff33cc; } .bestSeller h1 { color: #ff00cc; } $ config = array (); $ config ['path_to_css_dir'] = '../'; // <i> this is a root for css and xcss directories </ i> $ config ['xCSS_files'] = array ( 'styles / main.xcss' => 'generated / main.css', // file name xcss => save as ); $ config ['master_file'] = true; <i> // Use the master file (the file in which all styles will be included), true by default </ i> $ config ['master_filename'] = 'master.css'; <i> // respectively, the name of the master file, the default is 'master.css' </ i> $ config ['reset_files'] = array ( 'static / reset.css', <i> // Styles that reset default browser settings </ i> ); $ config ['hook_files'] = array ( 'static / hooks.css: screen', <i> // Files for other media types (I could be wrong) </ i> ); $ config ['construct_name'] = 'self'; <i> // The name of the element within itself, the default is 'self' </ i> $ config ['compress'] = true; <i> // Remove extra spaces, false by default </ i> $ config ['debugmode'] = false; <i> // Turns on debug mode, defaults to false </ i> $ config ['disable_xCSS'] = false; <i> // Disables xCSS, defaults to false </ i> $ xCSS = new xCSS ($ config); $ xCSS-> compile ();
/>Source: https://habr.com/ru/post/72241/
All Articles