我有一个简单的 React js 项目。
应用程序.js
import React from 'react';
import Radium, { StyleRoot } from 'radium';
import Checkbox from './Checkbox';
function App() {
// style
const style = {
':hover': {
color: 'red',
backgroundColor: 'blue'
},
':focus': {
color: 'orange'
}
};
return (
<div className="App">
<p>Hovering on the button should change its color to red and background color to blue.</p>
<p>Pressing it makes the text orange.</p>
<p>Pesudo-element like :hover is not possible unless we use radium.</p>
<button style={style}>Hover me</button>
<Checkbox />
</div>
);
}
export default Radium(App);
复选框.js
import React from 'react';
import Radium from 'radium';
const checkBox = props => {
const style = {
'+ label': {
color: '#ccc'
},
':checked + label': {
color: '#f00'
}
};
return (
<div>
<input type="checkbox" id="ossm" name="ossm" style={style} />
<label for="ossm">CSS is Awesome</label>
</div>
);
};
export default Radium(checkBox);
首先,我试图设置一个复选框的样式,以便:
- 它的标签颜色为#ccc,并且
- 选中后,将其标签的颜色更改为#f00。
不应用样式。如何解决?
其次,在 App.js 内部,我在什么情况下用 包装 JSX 代码<StyleRoot></StyleRoot>
?
非常感谢!