You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
normalizes for camel and dash case (see to-camel-case)
detects vendor prefixes as necessary, cached for performance (see prefix-style)
converts numbers to px strings for common properties (see add-px-to-style)
varcss=require('dom-css')//set a stylecss(element,'position','absolute')//will be set as "WebkitFontSmoothing" on Chromecss(element,'font-smoothing','none')//set multiple stylescss(element,{// can be camel or dash case'background-color': 'blue',// you can use numbers to auto-"px"left: 25,top: 0,marginTop: 0,position: 'absolute',// certain props will not have "px" addedopacity: 0.5})//get the current stylecss.get(element,'position')// -> 'absolute'css.get(element,['left','marginTop'])// -> { left: '25px', marginTop: '0px' }
Note: The get() method does not compute an element's style, it only fetches the currently set inline style.
Usage
css(element, property, value)
css.set(element, property, value)
Styles an element with the css property (dash or camel case) and a given value. value is a string, or a number to be suffixed with 'px' (special cases, see below).
css(element, styles)
css.set(element, styles)
A shorthand for setting multiple styles, where styles is an object containing property:value pairs.
css.get(element, prop)
Gets the inline style of element, where prop is a string (like "borderRadius") or an array of strings. If an array of strings is given, an object is returned with key-value pairs representing the specified properties.
This does not provide the computed style, only the current inline style.
auto px
If a number is specified, the value will have "px" added to it, unless it is a special unitless property like 'opacity' and 'zIndex'. See the full list in add-px-to-style (sourced from React).