Saya mencoba untuk mengatur gaya inline saya Bereaksi aplikasi. Dalam hal ini, untuk rentang:
<span className="myClass" style={{float : 'left', paddingRight : '5px'}} > </span>
Bereaksi memberitahu saya:
Tertangkap Pelanggaran Lain: The
gaya
prop mengharapkan pemetaan dari style properti untuk nilai-nilai, bukan sebuah string. Misalnya, style={{marginRight: jarak + 'em'}} ketika menggunakan JSX. DOM ini node diberikan oleh `SentenceView
Saya tidak yakin apa artinya.
PS: saya telah mencoba versi yang berbeda, jadi saya tidak paddingRight: 5
serta paddingRight: 5 + 'px'
serta paddingRight : 5px
, tapi aku tidak't memiliki sukses!
Ada beberapa cara untuk mengatur style untuk Bereaksi Komponen.
https://facebook.github.io/react/docs/context.html
https://github.com/facebookincubator/create-react-app
menggunakan className="anda-kelas-nama"
menggunakan style={css_object}
atau gaya={{color: ini.alat peraga.warna}}
stylesheet.css
import './styles.css';
/*
.classname-color{
color: "red";
background: "#0f0";
}
*/
const BTN = (props) => {
return (
<div>
My name is <button>{props.name}</button>
<hr/>
I'm <span className="classname-color">{props.age}</span> yeas old!
</div>
);
};
const infos = {
name: "xgqfrms",
age: 23
};
ReactDOM.render(<BTN {...infos} />, mountNode);
.classname-color{
color: "red";
background: "#0f0";
}
// <span style={styles}>
const styles = {
color: "red",
background: "#0f0",
fontSize: "32px"
};
const BTN = (props) => {
return (
<div>
My name is <button>{props.name}</button>
<hr/>
I'm <span style={styles}>{props.age}</span> yeas old!
</div>
);
};
const infos = {
name: "xgqfrms",
age: 23
};
ReactDOM.render(<BTN {...infos} />, mountNode);
// <span style={{color: styles.color}}>
const styles = {
color: "red",
background: "#0f0",
fontSize: "32px"
};
const BTN = (props) => {
return (
<div>
My name is <button>{props.name}</button>
<hr/>
I'm <span style={{color: styles.color}}>{props.age}</span> yeas old!
</div>
);
};
const infos = {
name: "xgqfrms",
age: 23
};
ReactDOM.render(<BTN {...infos} />, mountNode);
Ini adalah cara bagaimana anda dapat mendefinisikan dan menggunakan gaya inline dengan bereaksi.
/**
* Style definitions.
*/
const STYLE = {
infoColor: {
color: 'green'
},
warningColor: {
color: 'orange'
},
errorColor: {
color: 'red'
}
};
/**
* Component
*/
class Welcome extends React.Component {
/**
* Rendering into the DOM.
*/
render() {
return (
<div>
<h2 style={STYLE.infoColor}>Welcome!</h2>
)
}
}
Dalam HTML itu ``html
`` Di BEJ anda menulis ``bej `` Bersyarat inline format yang berbeda dalam kedua.