import "./index.css";
const App = () => (
<div className="App">My app</div>
)
// App.css
.root { padding-top: 1em; }
// Card.css
.root { padding-top: 2em; }
// Result
.root { padding-top: ??; }
.input:focus {
outline: 1px solid brown;
}
.select:focus {
outline: 1px solid brown;
}
.app {font-size: 2rem;}
.missing-class {color: red}
import "./index.css";
const App = () => <div className="app">
My app
</div>
import styles "./app.module.css";
const App = () => <div className={styles.root}>My app</div>
[filename]\_[classname]\_\_[hash]
import "./index.css";
const App = () => <div className="app">My app</div>
My app
:root { --main-color: black; }
body { var(--main-color, white) }
This will not work
CSS with superpowers
$default-padding: 1em;
.app{
padding: $default-padding;
}
.card {
padding: $default-padding;
}
.radio:disabled { opacity: 0.33; }
.radio:focus { outline: 1px solid red; }
.radio {
&:disabled { opacity: 0.33; }
&:focus { outline: 1px solid red; }
}
@mixin theme($theme: white, $txt: black) {
background: $theme;
color:$txt;
}
.card {
@include theme;
}
@use "sass:math";
article[role="main"] {
width: math.div(600px, 960px) * 100%;
}
import styled from "@emotion/styled";
const AppH1 = styled.h1`
color: red;
`;
In CSS in JS approach - css is a part of your code. Thus you have full control on it. You can use variables, math, any kind of transformation. You can use props to control any css property
Within CSS in JS you will not spot naming issues. Class names are unique or not exists at all
As far as CSS turned into the code - it's much easier to track, rename or delete CSS without worrying that something will be broken
import styled from "@emotion/styled";
const AppH1 = styled.h1`
color: red;
`;
const AppH1 = styled.h1<{ type: "regular" | "danger" }>`
color: ${({ type }) ==>
(type === "regular" ? "black" : "red")};
`;
const AppHeader = styled.h1<{ type: "regular" | "danger" }>`
color: ${({ type }) =>
(type === "regular" ? "black" : "red")};
`;
const FixSizeHeader = styled(AppHeader)`
font-size: 10px;
`;
import styles from './app.css';
import styles from './app.module.css';
const App = ()=> <div className="main"></div>
const App = ()=> <div className={styles.main}></div>