Home > Web Front-end > JS Tutorial > How to introduce css styles in react

How to introduce css styles in react

王林
Release: 2021-01-18 17:43:59
Original
3465 people have browsed it

How to introduce css style in react: first declare the style in the render function, such as [render() {let mystyle = {}}]; then reference the style, such as [return(

);].

How to introduce css styles in react

The environment of this article: windows10, react16&&css3 version, Dell G3 computer.

(Learning video sharing: react video tutorial)

React has three ways to introduce css styles:

1. Inline style: directly in the component Internal definition

<div style={{width:&#39;20px&#39;,height:&#39;30px&#39;}}>
    First Way!
</div>
Copy after login

2. Declaration style: first declare in the render function, and then quote

render() {
    let mystyle = {
         width:&#39;20px&#39;,
         height:&#39;30px&#39;
    }

    return(
        <div style={mystyle}>
            Second Way!
        </div>
    );
}
Copy after login

3. Introduce style: introduce external css file, the external css file is ordinary css. Use the following statement after the import statement in the component js.

requre(&#39;./mystyle.css&#39;);
Copy after login

Related recommendations: js tutorial

The above is the detailed content of How to introduce css styles in react. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template