[英]React js css inline style margin right not working
I want to implement margin-right inline CSS to the below react span element: 我想在下面的反应范围元素中实现margin-right内联CSS:
import React, { Component } from "react";
class NavBar extends Component {
state = {
totalCounters: 0,
};
render() {
let styles = {
margin-right: '20px',
width: '250px',
height: '250px',
backgroundColor: 'yellow',
};
return (
<nav className="navbar navbar-light bg-light">
<a className="navbar-brand" href="#">
Navbar
</a>
<span style={styles} className="badge badge-pill badge-secondary">
{this.props.totalCounters}
</span>
</nav>
);
}
}
export default NavBar;
But it shows syntax error, while no error if replacing margin-right
with margin
. 但它显示了语法错误,而如果更换没有错误
margin-right
与margin
。 So how to do it? 那怎么办呢?
React uses camelCase for inline style properties. React使用camelCase进行内联样式属性。 Try
marginRight: '20px'
, just like you did with backgroundColor
. 尝试
marginRight: '20px'
,就像你使用backgroundColor
。
try this: way a) 试试这个:方式a)
let styles = {
marginRight: '20px',
width: '250px',
height: '250px',
backgroundColor: 'yellow',
};
<span style={styles} className="badge badge-pill badge-secondary">
way b) 方式b)
<span style={{margin-right:"20px", width: '250px',height: '250px',background: 'yellow'}} className="badge badge-pill badge-secondary">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.