Home > Web Front-end > JS Tutorial > body text

Detailed explanation of using style binding in React

php中世界最好的语言
Release: 2018-05-24 14:24:11
Original
1485 people have browsed it

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;
}
Copy after login

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')
)
Copy after login

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>
        )        
    }
}
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!