How can I style React-Table? - javascript

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?

For React-Table v6, you can basically do it in 2 ways if you want to use css files.
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
Ad 1:
import "react-table/react-table.css"
import "./your_own_styles.(s)css"
Ad 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
Or start by copying the react-table/react-table.css from the react-table npm package (in your node_modules).

Definitely do not change the node_modules. You can either style inline or attach styles.
https://reactjs.org/docs/faq-styling.html

Definitely override the CSS classes with your own file. That's common practice for styling components from libraries.

Related

Overriding Bootstrap with custom css

I use npm I bootstrap in reactjs project , but I want to modify some of the elements, so I wrote my own custom.css. However it doesn't make any changes (only when I put !important, but the file is so large so it's not a good option).
import these in index.js
import "bootstrap/dist/js/bootstrap.bundle.min";
import "bootstrap/dist/css/bootstrap.css"
and in a single component, I have use bootstrap classes but It affects my all components and also inline custom CSS Style

How to import CSS files to React JS application?

I am creating an application, created multiple CSS files but those are not able to import.
I tried by installing css-loader and style-loader. But it doesn't help
Please look below picture, I have Burger.css file. but it not visible to import
VS Code by default doesn't autocomplete all file types. If you write import ./Burger/Burger.css or import ./Burger/BurgerIngredient/BurgerIngredient.css in your Layout.js file, your css files will be loaded fine.
If you want to use autocomplete for all files in VS Code, you can use this extension.
https://marketplace.visualstudio.com/items?itemName=ionutvmi.path-autocomplete
Without Extension
With Extension
Ok since you confirmed that your ./Layout.css import does not work, you should not name your import when it's about a css file. Doing :
import './myFile.css';
is enough to apply your css.
Note that css is global in React, so you might want to use styled component or encapsulate your css to prevent side effect on other components).
Now, if you really want to add style the way you tried to, there is the style attribute which accepts an object. So you could do:
<div style={{backgroundColor: 'red'}}>Hello World !</div>
Note that the css properties are written in camelCase.
Your file structure appears to me to be...
-Burger
--BurgerIngredient
----Burger.css
--Layout
----Layout.css
Your primary application, from what it appears here, is in /Burger. Considering that, when you type import, you see the dropdown appear, showing helpful suggestions, and it lists...
-../Burger/BurgerIngredient/...
As a possible, valid location. In that case, why don't we try importing css, by typing out...
import burgercss from '../Burger/BurgerIngredient/Burger.css';
Note, for instance, Burger.css wouldn't show up until you select BurgerIngredient, because that's its conntaining folder.

Bootstrap cdn overrides my custom css styles in react js

I have designed a web page in ReactJS using CSS. For one of the component I have used Bootstrap for styling. I garbed the latest bootstrap cdn link and pasted it in "index.html" file. When I use that bootstrap link, it overrides few of my custom styles. Each component of my project has a separate CSS and JS file. Please suggest any solution, where should I put that bootstrap link in my project so that it doesn't override my custom css styles. Thanks.
It's smell like wrong css include order. You may check it in browser. To resolve this, you can go through few ways:
Try to include bootstrap css as very first link in head section (after meta).
Try to include your css via import in your index.js file.
Second way should be look like this:
import "https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css";
import "./styles.css";
It’s very simple. Link your custom CSS file just below the bootstrap.css and override the class in your custom.css file.
You can rely on descendant selectors, ID and ‘!important’ notation together to override the styles but that is against the CSS best practices. You can use them only when it is absolutely necessary.
You can simply use this method. Follow the following articles. I hope you help this.
Override Bootstrap CSS styles
CSS Overrides

How do I use different CSS reset stylesheets through CRA?

There is a section in create-react-app about adding a css reset.
From what I understand, CRA includes PostCSS Normalize as a dependency, and all you need to do is create a css file and add #import-normalize; to it, and you will have normalize.css. (By the way, my editor gives me "Unknown CSS at-rule" with this #import-normalize).
What I want is a reset that includes having the margin on body be zero. I can't even tell if the reset is being applied just by looking at my app. I just want to make sure: this setting is not actually included in the normalize.css that is included by following the instructions?
Also, where can I find an explanation of what #import-normalize means? I haven't seen this syntax before.
Finally, is there a way through CRA to use a different reset file, or should I just install another one and import it as usually done?
Here is a bit of background on normalize.css
http://nicolasgallagher.com/about-normalize-css/
With CRA you can normalize/reset CSS with any method you like. You just need to create a stylesheet with the reset/normalized CSS rules in it and import it into App. i.e import './myCustomReset.css
or you can also add the reset CSS file to the public folder, and add it as a link tag to your index.html. i.e <link rel="stylesheet" href="./customResetStyles.css">
I tend to use https://gist.github.com/DavidWells/18e73022e723037a50d6 whenever I need to reset styles instead of just normalizing.

How to make changes to the style of the elements that make up a node module component?

I npm installed 'react-select' to my meteor-react project and I was trying to make style changes to the internal elements of the "Select" component from the package. I was able to make style changes in the Developer Options of the browser, but not able to find the source stylesheet to make the changes in.
Where can I find the stylesheets in the node module/package?
How do I make style changes to a node module/package?
react-select adds style to element using JavaScript. That's why we can not see any css/less/scss files in node_modules->react-select folder.
It is not the rule but recommendation that, don't ever try to alter the default style provided, instead override them.
My suggestion is override the style in your custom css files using the class-name/id of the element.

Categories

Resources