You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
898 B
898 B
id | title | layout | permalink | prev | next |
---|---|---|---|---|---|
style-prop-value-px | Shorthand for specifying pixel values in style prop | cookbook | style-prop-value-px.html | jsx-root-node-count.html | children-prop-type.html |
Problem
It's tedious to specify an inline style
value by appending your number value with the string "px" each time.
Solution
React automatically appends the string "px" for you after your number, so this works:
/** @jsx React.DOM */
var divStyle = {height: 10}; // rendered as "height:10px"
React.renderComponent(<div style={divStyle}>Hello World!</div>, mountNode);
Discussion
See Inline Styles for more info.
Sometimes you do want to keep the CSS properties unitless. Here's a list of properties that won't get the automatic "px" suffix:
- fillOpacity
- fontWeight
- lineHeight
- opacity
- orphans
- zIndex
- zoom