javascript 我如何设计 React-Table 的样式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53841626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I style React-Table?
提问by Jeff Goes
I am using react-table to create a filterable table, however I wanted to style it the way I want. 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?
我正在使用 react-table 创建一个可过滤的表,但是我想按照我想要的方式设置它的样式。我应该直接在 node_modules 应用程序中更改它,还是应该创建自己的 CSS 文件并即时覆盖检查元素?
回答by acidjunk
For React-Table v6, you can basically do it in 2 ways if you want to use css files.
对于 React-Table v6,如果要使用 css 文件,基本上可以通过 2 种方式进行。
Start with the css file from the npm package and override pieces you want to change
Start with your own css file and style everything that needs to be styled
从 npm 包中的 css 文件开始并覆盖要更改的部分
从您自己的 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。
回答by mediaguru
Definitely do not change the node_modules. You can either style inline or attach styles.
绝对不要更改 node_modules。您可以设置内联样式或附加样式。
回答by Nick Brady
Definitely override the CSS classes with your own file. That's common practice for styling components from libraries.
绝对使用您自己的文件覆盖 CSS 类。这是对库中的组件进行样式设置的常见做法。

