QueryPath\DOMQuery::css PHP Метод

css() публичный Метод

This sets the CSS value for each element in the DOMQuery object. It does this by setting (or getting) the style attribute (without a namespace). For example, consider this code:
public css ( mixed $name = null, string $value = '' )
$name mixed If this is a string, it will be used as a CSS name. If it is an array, this will assume it is an array of name/value pairs of CSS rules. It will apply all rules to all elements in the set.
$value string The value to set. This is only set if $name is a string.
    public function css($name = null, $value = '')
    {
        if (empty($name)) {
            return $this->attr('style');
        }
        // Get any existing CSS.
        $css = array();
        foreach ($this->matches as $match) {
            $style = $match->getAttribute('style');
            if (!empty($style)) {
                // XXX: Is this sufficient?
                $style_array = explode(';', $style);
                foreach ($style_array as $item) {
                    $item = trim($item);
                    // Skip empty attributes.
                    if (strlen($item) == 0) {
                        continue;
                    }
                    list($css_att, $css_val) = explode(':', $item, 2);
                    $css[$css_att] = trim($css_val);
                }
            }
        }
        if (is_array($name)) {
            // Use array_merge instead of + to preserve order.
            $css = array_merge($css, $name);
        } else {
            $css[$name] = $value;
        }
        // Collapse CSS into a string.
        $format = '%s: %s;';
        $css_string = '';
        foreach ($css as $n => $v) {
            $css_string .= sprintf($format, $n, trim($v));
        }
        $this->attr('style', $css_string);
        return $this;
    }