Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline CSS issues in react component

Tags:

css

reactjs

I have a react component and I'm trying to align the below div using margin-left property. I'm getting a console error:

Unexpected token

pointing towards the hyphen in the margin left property. Can anyone help to resolve this?

<div id="loadingDiv" style = {{display:'block'}}>
    <img src={Loading} style = {{width:150,height:150,margin-left:370}} />
</div>
like image 434
knbibin Avatar asked Apr 21 '17 05:04

knbibin


1 Answers

Write it like this:

style = {{ width : 150, height : 150, marginLeft : 370 }}

Instead of using margin-left use marginLeft.

Reason:

In React, inline styles are not specified as a string. Instead they are specified with an object whose key is the camelCased version of the style name, and whose value is the style's value, usually a string.

margin-left      -->   marginLeft 
padding-top      -->   paddingTop 
background-color -->   backgroundColor

Check the DOC.

like image 161
Mayank Shukla Avatar answered Sep 24 '22 18:09

Mayank Shukla