CSS tools for PHP.
Download a latest package or use Composer:
composer require czproject/css-tools
CzProject\CssTools requires PHP 7.4 or later.
Expands @import
rules in file.
$compiler = new CzProject\CssTools\CssCompiler;
$compiler->compileFile(__DIR__ . '/styles.css'); // overwrite styles.css with compiled version
$compiledStyles = $compiler->processFile(__DIR__ . '/styles2.css');
$compiledStyles = $compiler->processContent(
'@import "mystyles.css";',
$stylesheetsRootDirectory
);
$file = new CzProject\CssTools\CssFile;
$file->addRule('.button', [
'color' => CssTools\Color::hex('#F8A'),
'font-size' => CssTools\Number::px2rem(48),
'background-color' => NULL,
]);
echo $file->render();
$minifier = new CzProject\CssTools\CssMinifier;
$result = $minifier->minify("body {
color: #333;
background: #fff;
}");
var_dump($result); // Output: body{color:#333;background:#fff}
License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/