PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Aleksandar Zivanovic   PHP CSS Generator   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP CSS Generator
Compose and generate CSS programmatically
Author: By
Last change: changed

require_once __DIR__ . '/CssGenerator.php';
require_once __DIR__ . '/CssRule.php';

to

require_once __DIR__ . '/class.CssGenerator.php';
require_once __DIR__ . '/class.CssRule.php';
Date: 8 years ago
Size: 2,068 bytes
 

Contents

Class file image Download
<?php

error_reporting
(E_ALL);
ini_set('display_errors', true);

require_once
__DIR__ . '/class.CssGenerator.php';
require_once
__DIR__ . '/class.CssRule.php';

$css = new CssGenerator();

$css->defineIdRule('app') // #app -> defines rule with ID as selector and "app" as selector value
   
->set('width', '900px') // #app -> sets property width of #app
   
->set('margin', '0 auto') // #app -> sets property margin of #app
   
->defineClassSubRule('container') // #app .container -> creates CLASS rule as rule inside #app
   
->set('padding', '100px') // #app .container -> sets property padding of #app .container
   
->set('color', 'red') // #app .container -> sets property color of #app .container
   
->defineClassRule('small') // #app .container.small -> creates CLASS rule that is additional class of .container
   
->set('width', '20px') // #app .container.small -> sets property width of #app .container.small
   
->set('color', 'purple') // #app .container.small -> sets property color of #app .container.small
   
->getParent() // #app .container -> moves pointer to first parent
   
->defineClassChildRule('small') // #app .container > .small -> defines DIRECT CHILD rule to #app .container
   
->set('color', 'blue') // #app .container > .small -> sets property color of #app .container > .small
   
->getParent('app') // #app -> moves pointer to first parent with identifier value "app"
   
->set('background-color', 'silver'); // #app -> sets property background-color of #app

file_put_contents('style.css', $css->generate());

?>
<html>
    <head>
        <title>CSS Generator</title>
        <link rel="stylesheet" href="style.css" />
    </head>
    <body>
    <div id="app">
        <div>
            <div class="container">
                <div class="small">
                    .container > .small
                </div>
                .container
            </div>
        </div>
        <div class="container small">
            .container.small
        </div>
    </div>
    </body>
</html>