How to apply shared css file between multiple components in React? - css

I developed a ReactJs app that contain multiple components which every one of them have a seperate css file.
But now i need to clean up and have a shared css file that contains the commun styles for all of the components.
I want to have it done the best way.
I would love to have some suggestions.

How about using Sass and then working with mixins?

For this, also use a import statement in css files, or you can import all css files into index.jsx file

Related

Same css is working for all components without importing it

I am learning react in which I am making components and making css file for each component but if I make a className lets say "temporary" then if I make another component and while I am not importing the previous component's css file but then also if i give the class "temporary" to any other element of this component then also it take the css styling. Why is this happening I don't know.
You create multiple CSS files and several components in your React project and connect them if needed.
But this is what you see, not what happens.
React actually converts all your CSS code into a file and then outputs it.
This is also true for components.
You create dozens of CSS and JS files, but React creates two files for you.
In Recycling, we only create a few files to write more readable code.
If you have a problem with this, you can research the module.css in React and use it to prevent this from happening to you.
Again, if you have any questions about this, I am at your service.

With Svelte : How to put component style in a separated file but still scoped to this component

I'm working on a table component which one will be usable (included in a library when it will work correctly)in any of my projects.
As there is a lot of css rules related to this component I would like to put the style outside of the component svelte file.
What I did is writing a separate css file which I import in the component svelte file by :
import './table.css';
But in such a case I can see my rules in the built bundle.css file but these are not scoped to my component.
So I'm wondering if there is way of doing it as I would like or not....
yes, when svelte-preprocess is set up, you can use <style src="./table.css"></style> in the .svelte file
https://github.com/sveltejs/svelte-preprocess#external-files
...https://discord.com/channels/457912077277855764/945368391231864832/945369571680997416

Using SCSS and CSS together

Apologies if the following doesn't make sense,
I'm very curious about one thing, using SCSS & CSS file together in same website. My question is can we actually use SCSS and CSS together?
It is now possible to import CSS files directly into your sass file. The following PR in GitHub solves the issue. The syntax is the same as now - #import "your/path/to/the/file", without an extension after the file name. This will import your file directly.

How to import CSS files in vue components with scope limited to components only?

How do I import CSS files into vue components so that the scope of those files limited to components only, I tried importing the files into style tab in a single component file with the scoped property but it still bundles all the CSS and overriding one another? Is there any way I can import CSS files with scoped limited to Single file component? I don't want my CSS to be overwritten by other component CSS files? and one more thing I am using webpack cli 3. Thank you so much for your time. Will appreciate the help.
Finally after so much googling and hits and tires i found one answer. we can do something like this in the Single File Component. this will make you CSS src file scoped to your component only. Thank you for your time!
<style scoped src="#/assets/css/main.css"></style>

import of SASS partials in Angular2 components

I am using SASS for designing my website and have developed some partials in separate file say _partials.scss. Now I want to use these variables and mixins in my scss files of various components. So I imported this scss to styles.scss file which is present inside the \src folder. But the mixins & variables are not available to each of the component level scss files.
So, next I import these partials to each of the component scss files. This works fine. But is this a good approach to import the partials in all the component stylesheets? What can be a better solution to this?
P.S. I am using Angular CLI and webpack. Angular 2 version 2.3.0
Thanks!
This is a good approach. Every .scss file in your project should know it's dependencies, that's why the #import is always good.
What you can improve is adding the partials to the includePaths (if you use node-sass), that you can directly use #import 'partials'; instead of #import '../../my/long/path/to/partials'; or do the styles as a single file (not component level styles).
in style.sass you can import css / scss link.

Resources