PEAR logo

HTML_CSS : The Definitive Guide

Handle group selector

With HTML_CSS::addGroupSelector() and HTML_CSS::removeGroupSelector(), we have ability to add or remove one selector from a selectors list (of a group).

Suppose we have these selectors :

html, body { margin: 2px; padding: 0; border: 0; }
     

and we want to apply same share properties to new class 'large' and do not anymore apply it to 'body'.

Here are how to do :

      
<?php
require_once 'HTML/CSS.php';

$css = new HTML_CSS();

// 1. create the pre-requires data
$g1 = $css->createGroup('html, body');
$css->setGroupStyle($g1, 'margin', '2px');
$css->setGroupStyle($g1, 'padding', '0');
$css->setGroupStyle($g1, 'border', '0');

// 2. remove the body selector
$css->removeGroupSelector(1, 'body');

// 3. add the new 'large' class
$css->addGroupSelector(1, '.large');

$css->display();
?>
      
     

[Note] Note
Remember that HTML_CSS handle group (numeric) identifier itself (begin at 1, and go to 2, 3, and more).

HTML_CSS : The Definitive Guide v 1.0.0 : June 24, 2006