PHP code example of devly / css-generator

1. Go to this page and download the library: Download devly/css-generator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

devly / css-generator example snippets


use Devly\CssGenerator\CSS;
$options = [
    'indent' => 4, // Default indent: 4 spaces
    'minify' => false, // Default false
];
$css = CSS::new([], $options);
$css->charset('utf-8');
$css->import('path/to/imported.css');
$css->import('path/to/second-imported.css')
    ->supports('display: block')
    ->media('screen');
$css->selector('body')
    ->fontFamily('Arial, sans-serif')
    ->fontSize('16px')
    ->lineHeight(1.5);
$css->media('screen and (min-width: 768px)')
    ->selector('body')
    ->fontSize('18px')
    ->endMedia();

echo $css->compile();

$minify = true; // Will override minify option if already set
$override = true; // Override if file exists
$mkdir    = true; // Creates directory recursively if not already exists
$css->save('path/to/compiled.css', $minify, $override, $mkdir);

use Devly\CssGenerator\CSS;

$imported = CSS::new()->selector('body')->backgroundColor('#000000');

$css = CSS::new($imported)

use Devly\CssGenerator\CSS;

$mobile_css = CSS::new()->selector('body')->backgroundColor('#000000');

$css = CSS::new()->media('screen and (max-width: 768px)', $mobile_css);