Socket
Socket
Sign inDemoInstall

dom-css

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dom-css

fast dom CSS styling


Version published
Weekly downloads
269K
increased by2.91%
Maintainers
1
Weekly downloads
 
Created
Source

dom-css

stable

Small module for fast and reliable DOM styling.

  • detects prefixes as necessary, cached for performance
  • converts numbers to px strings for common properties
  • normalizes for camel and dash case
var css = require('dom-css')

//set a style
css(element, 'position', 'absolute')

//will be set as "WebkitFontSmoothing" on Chrome
css(element, 'font-smoothing', 'none')

//set multiple styles
css(element, {
    //can be camel or dash case
    'background-color': 'blue',

    //some properties use 'px' by default
    left: 25, 
    top: 0,
    position: 'absolute'
})

See the special cases for a list of px-suffixed properties (same list is used in GreenSock API).

Usage

NPM

css(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)

A shorthand for setting multiple styles, where styles is an object containing property:value pairs.

special cases

The following properties are suffixed with 'px' when their value is specified as a number.

top, right, bottom, left, 
width, height, fontSize, 
paddingLeft, paddingRight, 
paddingTop, paddingBottom, 
marginLeft, marginRight, 
marginTop, marginBottom, 
padding, margin, perspective

License

Special thanks to Paul Irish's gist for the prefix detection (now part of Modernizr).

MIT, see LICENSE.md for details.

Keywords

FAQs

Package last updated on 07 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc