【React】样式控制

组件基础样式控制

行内样式(不推荐)

方式1

  • function App() {
        return (
            <div>
                <span style={{color: 'red', fontSize: '50px'}}>this is span</span>
            </div>
        );
    }
    ...
    

方式2

  • const style = {
        color: 'red',
        fontSize: '50px'
    }
    
    function App() {
        return (
            <div>
                <span style={style}>this is span</span>
            </div>
        );
    }
    ...
    

class类名控制

  • import './index.css'
    
    function App() {
        return (
            <div>
                <span className="foo">this is span</span>
            </div>
        );
    }
    ...
    
posted @ 2024-09-01 11:41  505donkey  阅读(24)  评论(0)    收藏  举报