Home >Web Front-end >JS Tutorial >Detailed explanation of using style binding in React

Detailed explanation of using style binding in React

php中世界最好的语言
php中世界最好的语言Original
2018-05-24 14:24:111518browse

This time I will bring you a detailed explanation of the use of style binding in React. What are the precautions when using style binding in React. The following is a practical case, let's take a look.

Use common style names—— className

app.css

.c1{
    color: red;
    width: 100%;
    height: 300px;
    border: solid 1px red;
}

app.js

import './app.css'
import React from 'react';
import ReactDOM from 'react-dom';
import './modules/cp/cp.scss'
class Component1 extends React.Component{
    render(){
        return (
            <p className="c1"></p>
        )        
    }
}
ReactDOM.render(
    <Component1 />,
    document.getElementById('app')
)

Inline style

let c1 = {
    color: 'red',
    width: '100%',
    height: '300px',
    border: 'solid 1px red'
}
class Component1 extends React.Component{
    render(){
        console.log(c1)
        return (
            <p style={c1}></p>
        )        
    }
}

Believe it or not After reading the case in this article, you have mastered the method. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Detailed explanation of the steps to select li highlighting in react

EasyCanvas drawing library is used in Pixeler project development Practical summary

The above is the detailed content of Detailed explanation of using style binding in React. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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