21
loading...
This website collects cookies to deliver better user experience
npx create-react-app chirp-landing-page
.scss
files and you can use them directly into your components without any need to convert them into .css
file first. Just install sass and you are good to go.
cd chirp-landing-page
npm install sass
src
folder.
📦src
┣ 📂assets
┣ 📂components
┣ 📂partials
┣ 📜App.js
┣ 📜base.scss
┗ 📜index.js
base.scss
consisted resets, import for fonts and some basic styles common to a lot of folders. The partials
folder consists of mixins, variables and breakpoints which can be used in any .scss
file by using @use
. The @use
namespaces the variables, mixins and functions within the file and thus avoiding name collision. You can also give it an alias or use * to skip the namespace and use them directly.@use '../partials/variables' as v;
.text{
color: v.$red;
}
$breakpoints:('small':'768px','medium':'960px','large':'1200px');
@mixin breakpoint-up($size){
@media (min-width:map-get($breakpoints,$size)){
@content;
}
}
@mixin breakpoint-down($size){
@media (max-width:map-get($breakpoints,$size)){
@content;
}
}
_breakpoints.scss
and use it within the tag you want to style using @include
.@use '../partials/breakpoints';
.grid{
display: grid;
grid-template-columns: 1fr;
@include breakpoint-up(medium){
grid-template-columns: repeat(2,1fr);
}
}
import './Sample.scss';
const Sample = () => {
return (
<div className='container'>
<h1 className='title'>Hi 👋 Dev Community!</h1>
</div>
)
}
export default Sample
.scss
files in a specific way- *.module.scss
.(where * is the name of your file. Then import the file asimport classes from './Sample.module.scss';
classes
is an object returned by the file. Here, the keys are the name of your classes defined in the file. You can use them as<div className={classes.container}>
<h1 className={classes.title}>Hi 👋 Dev Community!</h1>
</div>
npm run build
command.