FluentDOM\Query::css PHP 메소드

css() 공개 메소드

get or set CSS values in style attributes
public css ( string | array $property, variadic<[string | object | callable]> $arguments ) : string | null | $this
$property string | array
$arguments variadic<[string | object | callable]>
리턴 string | null | $this
    public function css($property, ...$arguments)
    {
        if (count($arguments) == 0 && is_string($property)) {
            $properties = new Query\Css\Properties((string) $this->attr('style'));
            if (isset($properties[$property])) {
                return $properties[$property];
            }
            return NULL;
        }
        $values = $this->getSetterValues($property, isset($arguments[0]) ? $arguments[0] : NULL);
        //set list of properties to all elements
        $this->each(function (\DOMElement $node, $index) use($values) {
            $properties = new Query\Css\Properties($node->getAttribute('style'));
            foreach ($values as $name => $value) {
                $properties[$name] = $properties->compileValue($value, $node, $index, isset($properties[$name]) ? $properties[$name] : NULL);
            }
            if (count($properties) > 0) {
                $node->setAttribute('style', (string) $properties);
            } elseif ($node->hasAttribute('style')) {
                $node->removeAttribute('style');
            }
        }, TRUE);
        return $this;
    }

Usage Example

예제 #1
0
파일: Css.php 프로젝트: fluentdom/fluentdom
 /**
  * Allow to use array syntax to change a css property value on all matched nodes.
  *
  * @see ArrayAccess::offsetSet()
  * @param string $name
  * @param string $value
  */
 public function offsetSet($name, $value)
 {
     $this->_fd->css($name, $value);
 }