Skip to content

Instantly share code, notes, and snippets.

@SarahElson
SarahElson / Button.module.css
Created May 21, 2024 03:57
How to Use CSS Modules With React Applications
.button{
padding: 10px 20px;
border: none;
border-radius: 10px;
margin: 0 10px;
}
.primary{
composes:button;
background: linear-gradient(91.88deg,#2c57f3 .88%,#a506d8 98.71%);
color: white;
@SarahElson
SarahElson / Button.js
Created May 21, 2024 03:56
How to Use CSS Modules With React Applications
import React from 'react'
import styles from './Button.module.css'
export default function Button({text,type}) {
return (
<button className={styles.button + " " + styles[type]}>{text}</button>
)
}
@SarahElson
SarahElson / Navlinks.module.css
Created May 21, 2024 03:55
How to Use CSS Modules With React Applications
@SarahElson
SarahElson / Navlinks.js
Created May 21, 2024 03:53
How to Use CSS Modules With React Applications
@SarahElson
SarahElson / Navlinks.js
Created May 20, 2024 17:13
How to Use CSS Modules With React Applications
@SarahElson
SarahElson / Navbar.module.css
Created May 20, 2024 17:11
How to Use CSS Modules With React Applications
.navbar{
display: flex;
flex-direction: row;
height: 10vh;
padding:0 5rem;
justify-content: space-between;
align-items: center;
position: absolute;
top: 0;
left: 0;
@SarahElson
SarahElson / App.module.css
Created May 20, 2024 16:26
How to Use CSS Modules With React Applications
.app{
min-height: 100vh;
background-color: #fafafa;
width: 100%;
position: relative;
}
@SarahElson
SarahElson / App.js
Created May 20, 2024 16:25
How to Use CSS Modules With React Applications
import styles from './App.module.css'
import HeroSection from './components/HeroSection/HeroSection';
import Navbar from './components/Navbar/Navbar';
function App() {
return (
<div className={styles.app}>
<Navbar />
<HeroSection />
//Import the styles in a JavaScript file
import styles from './Card.module.css'
//use it as an object
<div class={styles.card}>
{/* Code related to card */}
</div>
.card{
/* Styles related to the card */
}