CSS properties in React are not automatically added with their vendor prefixes.
For example, with:
<div style={{
transform: 'rotate(90deg)'
}}>Hello World</div>
In Safari, the rotation wouldn't be applied.
How do I get that accomplished?
To set inline styles in React: Set the style prop on the element to an object. Set the specific CSS properties and values to style the element. For example, <div style={{backgroundColor: 'salmon', color: 'white'}}> .
The official React documentation frowns upon the use of inline styling as a primary means of styling projects and recommends the use of the className attribute instead.
The major browsers use the following prefixes: -webkit- (Chrome, Safari, newer versions of Opera, almost all iOS browsers including Firefox for iOS; basically, any WebKit based browser) -moz- (Firefox)
React does not apply vendor prefixes automatically.
In order to add vendor prefixes, name the vendor prefix as per the following pattern, and add it as a separate prop:
-vendor-specific-prop: 'value'
becomes:
VendorSpecificProp: 'value'
So, in the example in the question, it needs to become:
<div style={{
transform: 'rotate(90deg)',
WebkitTransform: 'rotate(90deg)'
}}>Hello World</div>
Value prefixes can't be done in this way. For example this CSS:
background: black;
background: -webkit-linear-gradient(90deg, black, #111);
background: linear-gradient(90deg, black, #111);
Because objects can't have duplicate keys, this can only be done by knowing which of these the browser supports.
An alternative would be to use Radium for the styling toolchain. One of its features is automatic vendor prefixing.
Our background example in radium looks like this:
var styles = {
thing: {
background: [
'linear-gradient(90deg, black, #111)',
// fallback
'black',
]
}
};
I don't have experience with react.js, but look at this js library from Lea Verou. It prefixes style direct in DOM.
http://leaverou.github.io/prefixfree/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With