[React] Styling a React button component with Radium
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[React] Styling a React button component with Radium相关的知识,希望对你有一定的参考价值。
React‘s inline styles allow components to stand on their own by not requiring any external CSS. However html‘s style attributes don‘t support pseudo selectors like :hover
and :active
. By using Radium to listen to mouse events we can restore :hover
and :active
selectors to inline styles.
const { render } = ReactDOM const rootEl = document.getElementById(‘root‘) const Div = Radium(({children}) => { return ( <div style={style}> {children} </div> ); }); const style = { backgroundColor: ‘#07d‘, border: ‘none‘, borderRadius: 4, color: ‘#fff‘, padding: ‘5px 20px‘, ‘:hover‘: { backgroundColor: ‘#08f‘ } } render(<Div>OK</Div>, rootEl)
So, just need to wrap the compoment in to Radium() method.
以上是关于[React] Styling a React button component with Radium的主要内容,如果未能解决你的问题,请参考以下文章
React-native:textAlign:'right'样式不正确
样式(tailwind/SCSS 样式表)未应用于 React 中动态插入的 HTML