text-alignis not a valid Javascript identifier, so you cannot use it as part of a literal in code. All of the examples below are not suitable for the same reason.
var text-align = 'right';
style.text-align = 'right';
var style = { text-align: 'right' };
Creating a property with a string is valid.
style['text-align'] = 'right';
var style = { 'text-align': 'right' };
const prop = 'text-align';
const style = { [prop]: 'right' };
Javascript .
, API , React .
document.body.style.textAlign = 'red';
React , , 70% '70%'.
, . ( CSS Clojure) . Javascript, React.
- :
import { px, em, percent } from 'units';
var width = 30;
const style = {
height: px(width * 2),
width: px(width),
margin: percent(5)
};
, , - .