QuickCSS
⚡️-fast tiny CSS management tool sprinkled with API sugar
Features
- fetch computed style values of elements.
- apply styles with either kebab-case or camel-case property names.
- automatic value conversion (
width:10 === '10px'
) - automatic browser prefixing
- global style registration
- animation registration
- check CSS browser support with
.supports()
and.supportsProperty()
- simple
!important
flag application - global style levels (i.e. overriding styles)
Table of Contents generated with DocToc
- Usage
- API
quickcss(element, property)
quickcss(element[], property, value[, important])
quickcss(element[], properties)
quickcss.animation(name, frames)
quickcss.register(rule[, level, important])
quickcss.clearRegisered([level])
quickcss.supports(property, value)
quickcss.supportsProperty(property)
quickcss.normalizeProperty(property)
quickcss.normalizeValue(property, value)
- Value normalization
- License
Usage
var quickcss = // Fetch *computed* styles //=> 133.92px // Apply styles //=> 100px //=> 50% // Multiple element application //=> 18px // Multiple style application // !important flag //=> opacity:0.5 !important // Deleting style //=> 'static' // Animation registration (with auto-prefixing)quickcss
API
quickcss(element, property)
Returns the element's computed value for the given property.
- element: DOM element object.
- property: CSS property in camel/kebab-case (
font-size
orfontSize
).
// Assuming that {fontSize:'2.5em'} //=> 40px
quickcss(element[], property, value[, important])
Formats and applies value
for the given property
on element
.
- element: DOM element object or an array of elements.
- property: CSS property in camel/kebab-case (
font-size
orfontSize
). - value: value that will be applied to
property
. For some properties, values will be normalized and translated to provide API sugar. - important: optional boolean to control the addition of
!important
flag.
quickcss(element[], properties)
Iterates over properties
, using the key as the property
and applies its value to the element
.
- element: DOM element object or an array of elements.
- properties: A
{property:value}
pair object.- property: CSS property in camel/kebab-case (
font-size
orfontSize
). - value: value that will be applied to
property
.
- property: CSS property in camel/kebab-case (
quickcss.animation(name, frames)
Registers the provided animation which can be used globally on the page. All properties will be automatically prefixed if needed.
- name: name of the animation
- frames: an object containing
{step:properties}
pairs.- step: CSS step string e.g.
50%
- properties: A
{property:value}
pair object.
- step: CSS step string e.g.
quickcss
quickcss.register(rule[, level, important])
Registers the provided rule
object globally and returns the class name string which can be added to any element later.
- rule: A
{property:value}
pair object.- property: CSS property in camel/kebab-case (
font-size
orfontSize
). - value: value that will be applied to
property
.
- property: CSS property in camel/kebab-case (
- level: the level to declare the rule under. The higher the level the higher the importance e.g. rules declared in level
2
will override rules declared in level1
and0
. Default level is0
. - important: boolean which when
true
will cause all declarations to be declared along with an!important
flag.
var newClass = quickcss elementclassName += ` ` //=> '100px'
quickcss.clearRegisered([level])
Clears/erases all of the globally registered rules for the given level
.
- level: the target level to clear styles of. Default level is
0
.
quickcss.supports(property, value)
Checks if the provided value
is a valid value for property
.
quickcss.supportsProperty(property)
Checks if the provided property
is supported by the browser.
quickcss.normalizeProperty(property)
Converts the property name into kebeb-case e.g. 'fontSize' ->
font-size``.
quickcss.normalizeValue(property, value)
Converts the value to a valid CSS value e.g. 50 ->
50px``.
Value normalization
For many properites you can supply a value with typeof number
instead of string
(i.e. 10 vs "10px"
) and the value will be automatically normalized to a px
string. These properties include width
, height
, margin-left
, font-size
, z-index
, and more (refer to REQUIRES_UNIT_VALUE).
There is one property that receives slightly different normalization which is the line-height
property. If a numerical value is provided, it will be converted to em
.
//=> '10px' //=> '10em'
License
MIT © Daniel Kalen