当前位置: 首页 > news >正文

react中修改组件样式的几种方法

  1. 使用自定义类名className,引入样式文件进行样式覆盖
import React from 'react';
import { Button } from 'antd';const MyComponent = () => {return (<Button className="custom-button">点击我</Button>);
};export default MyComponent;
.custom-button {background-color: blue;color: white;
}
  1. 使用内联样式
import React from 'react';
import { Button } from 'antd';const MyComponent = () => {return (<Button style={{ backgroundColor: 'blue', color: 'white' }}>点击我</Button>);
};export default MyComponent;
  1. 使用css module 中的 :global 进行全局样式覆盖
// test.module.css.container {padding: 20px;background-color: lightgray;
}/* 全局样式 */
:global(body) {font-family: Arial, sans-serif;margin: 0;padding: 0;
}
  1. 使用styled-components 编写样式化的组件
import React from 'react';
import { Button } from 'antd';
import styled from 'styled-components';const StyledButton = styled(Button)`background-color: blue;color: white;
`;const MyComponent = () => {return (<StyledButton>点击我</StyledButton>);
};export default MyComponent;
  1. 在根目录建立样式文件修改全局样式

http://www.mrgr.cn/news/17546.html

相关文章:

  • linux组合命令:删除一个目录树中所有的空目录(包括嵌套空目录)
  • Day 1 : 数据结构
  • CompletableFuture学习
  • 酿酒师的匠心独运:白酒酿造的不同工艺
  • 网络层 III(划分子网和构造超网)【★★★★★★】
  • 《C++自定义类型的流输入输出:解锁高效编程新维度》
  • 网络工程9(软路由,旁路由)
  • 【C++ Primer Plus习题】8.7
  • Linux操作系统软件管理
  • 垃圾回收机制
  • 2-83 基于matlab的自适应正则化核的模糊均值聚类框架(ARKFCM)
  • 学习记录:js算法(二十一):字符串的排列、替换后的最长重复字符
  • 如何实现图片垂直旋转90度的问题
  • HarmonyOS开发实战( Beta5版)应用滑动场景帧率问题分析最佳实践
  • IDEA插件开发中JavaProgramPatcher的使用
  • 【JUC】08-线程等待与唤醒
  • 搭建IPsec VPN隧道解决PLC设备与主控上位机无法使用公网IP进行通信的问题
  • [STM32]从零开始的STM32标准库环境搭建(小白向)
  • 【读书笔记-《30天自制操作系统》-13】Day14
  • Ai Illustrator 取消吸附到像素点,鼠标拖动的时候只能到像素点