简体   繁体   English

如何为React-Table设置样式?

[英]How can I style React-Table?

I am using react-table to create a filterable table, however I wanted to style it the way I want. 我正在使用react-table创建可过滤的表,但是我想用自己想要的方式对其进行样式设置。 Should I change it directly inside node_modules application or should I create my own CSS file and override inspecting the element on the fly? 我应该直接在node_modules应用程序中更改它,还是应该创建自己的CSS文件并覆盖动态检查元素?

For React-Table v6, you can basically do it in 2 ways if you want to use css files. 对于React-Table v6,如果要使用css文件,基本上可以用2种方法来实现。

  1. Start with the css file from the npm package and override pieces you want to change 从npm包中的css文件开始,覆盖要更改的部分

  2. Start with your own css file and style everything that needs to be styled 从您自己的css文件开始,并对需要样式化的所有内容进行样式化

Ad 1: 广告1:

import "react-table/react-table.css"
import "./your_own_styles.(s)css"

Ad 2: 广告2:

import "./your_own_styles.(s)css"

To get an idea what you can use in your own css file you can have a look at this gist: https://gist.github.com/sghall/380aa1055bcad4db22d1fc258d7f09d0 要了解您可以在自己的CSS文件中使用什么,请查看以下要点: https : //gist.github.com/sghall/380aa1055bcad4db22d1fc258d7f09d0

Or start by copying the react-table/react-table.css from the react-table npm package (in your node_modules). 或首先从react-table npm包(在您的node_modules中)复制react-table / react-table.css开始。

Definitely do not change the node_modules. 绝对不要更改node_modules。 You can either style inline or attach styles. 您可以设置内联样式或附加样式。

https://reactjs.org/docs/faq-styling.html https://reactjs.org/docs/faq-styling.html

Definitely override the CSS classes with your own file. 绝对用您自己的文件覆盖CSS类。 That's common practice for styling components from libraries. 这是对库中的组件进行样式设置的常见做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM