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 :

  1. 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 :

  1. <?php
  2. require_once 'HTML/CSS.php';
  3.  
  4. $css = new HTML_CSS();
  5.  
  6. // 1. create the pre-requires data
  7. $g1 = $css->createGroup('html, body');
  8. $css->setGroupStyle($g1, 'margin', '2px');
  9. $css->setGroupStyle($g1, 'padding', '0');
  10. $css->setGroupStyle($g1, 'border', '0');
  11.  
  12. // 2. remove the body selector
  13. $css->removeGroupSelector(1, 'body');
  14.  
  15. // 3. add the new 'large' class
  16. $css->addGroupSelector(1, '.large');
  17.  
  18. $css->display();
  19. ?>
[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.5.0 : January 15, 2008