Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply global styles with CSS modules in a react app?

I'm currently using CSS Modules with React for my styling. So each of my components is importing in it's component specific css file, like so:

import React from 'react'; import styles from './App.css';  const example = () => (   <div className={styles.content}>     Hello World!   </div> );  export default example; 

This works fine when styling individual components, but how do I apply global styling (html, body, header tags, divs, etc.) that isn't component specific?

like image 565
hidace Avatar asked Oct 01 '16 10:10

hidace


People also ask

Are CSS modules global?

According to the official CSS Module GitHub repository, a CSS Module is a CSS file in which all class names and animation names are scoped locally by default. By contrast, in a typical CSS file, all CSS selectors live in the global scope.

Can I use external CSS in React?

Importing external stylesheets As the name suggests, React can import CSS files. The process is similar to how we link up CSS file in the HTML <head> : Create a new CSS file in your project directory.

What is global CSS?

This setting displays the CSS files that are applied to all MicroStrategy Web pages. Since these CSS files are global in nature, they are defined in the main page templates and in the Global_Links file (JSP or ASP .


1 Answers

Since you're using the ES6 import syntax you may use the same syntax to import your stylesheet

import './App.css' 

Also, you can wrap your class with :global to switch to the global scope (this mean CSS Module won't modulify it, eg: adding a random id next to it)

:global(.myclass) {   background-color: red; } 
like image 71
felixyadomi Avatar answered Sep 18 '22 07:09

felixyadomi