HTML_CSS::setStyle
HTML_CSS::setStyle() – Set or add a CSS definition
Synopsis
require_once 'HTML/CSS.php';
void|PEAR_Error HTML_CSS::setStyle (
string $element
, string $property
, string $value
, bool $duplicates
= null
)
Описание
Add or change a single value for an element property
Parameter
-
string
$element
-
Element (or class) to be defined
-
string
$property
-
Property defined
-
string
$value
-
Value assigned
-
boolean
$duplicates
-
(optional) Allow or disallow duplicates.
See
Throws
throws HTML_CSS_ERROR_INVALID_INPUT
Since
since version 0.2.0 (2003-07-31)
Замечание
This function can not be called statically.
Пример
<?php
require_once 'HTML/CSS.php';
// generate an instance
$css = new HTML_CSS();
// let's set some styles for <body>
$css->setStyle('body', 'background-color', '#0c0c0c');
$css->setStyle('body', 'color', '#ffffff');
// now for <h1>
$css->setStyle('h1', 'text-align', 'center');
$css->setStyle('h1', 'font', '16pt helvetica, arial, sans-serif');
// and finally for <p>
$css->setStyle('p', 'font', '12pt helvetica, arial, sans-serif');
// let's make <body> inherit from <p>
$css->setSameStyle('body', 'p');
// and let's put this into a tag:
echo '<body style="' . $css->toInline('body') . '">';
// will output:
// <body style="font:12pt helvetica, arial, sans-serif;background-color:#0c0c0c;color:#ffffff;">
?>