当前位置:首页 > Web开发 > 正文

React 中使用CSS的要领

2024-03-31 Web开发

标签:

  不需要组件从外部引入css文件,直接在组件中书写。 import React, { Component } from "react";const div1 = {
  width: "300px",

  margin: "30px auto",

  backgroundColor: "#44014C", //驼峰法

  minHeight: "200px",

  boxSizing: "border-box"
};
  
class Test extends Component {
  constructor(props, context) {

    super(props);

}

  render() {

    return (

      <div>

    <div style={div1}>123</div>

    <div >  

  </div>

  );

 }
}
export default Test;


注意事项:
在正常的css中,好比background-color,box-sizing等属性,在style东西div1中的属性中,必需转换成驼峰法
backgroundColor,boxSizing。而没有连字符的属性,如margin,,width等,则在style东西中不乱。

React 中使用CSS的要领

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/31691.html