.section {
width: 100%;
}
.section .list {
padding: 20px;
}
.section .list li {
float: left;
}
.btn {
position: absolute;
}
.btn.active {
color: red;
}
.section {
width: 100%;
.list {
padding: 20px;
li {
float: left;
}
}
}
.btn {
position: absolute;
&.active {
color: red;
}
}
import styles from "./Box.module.css";
<div className={styles.Box} />
// ${styles.one} ${styles.two}
// ${styles.one} ${condition ? styles.two : ''}
CSS Module 별도로 설치해야 할 라이브러리는 없습니다. 이 기능은 webpack 에서 사용하는 css-loader 에서 지원되는데, CRA 로 만든 프로젝트에는 이미 적용이 되어있으니 바로 사용하면 됩니다.
classNames('foo', 'bar'); // => 'foo bar'
classNames('foo', { bar: true }); // => 'foo bar'
classNames({ foo: true }, { bar: true }); // => 'foo bar'
classNames({ foo: true, bar: true }); // => 'foo bar'
// bind version (for css-modules)
const styles = { foo: 'abc', bar: 'def', baz: 'xyz' };
const cx = classNames.bind(styles);
const className = cx('foo', ['bar'], { baz: true }); // => 'abc def xyz'
<div class="flex pt-4 text-center rotate-90" />
const Button = styled.a<{ $primary?: boolean; }>`
width: 10rem;
&:active {
opacity: 0.85;
}
${props => props.$primary && css`
background: yellow;
color: white;
`}
`;
const TomatoButton = styled(Button)`
color: tomato;
`;
// 또다른 사용 예시
// background: ${props => props.$primary ? "#BF4F74" : "white"};
// color: ${props => props.$inputColor || "#BF4F74"};
<Button $primary />
<TomatoButton />
import { css } from '@emotion/css';
<div
className={css`
padding: 32px;
`}
/>
import styled from '@emotion/styled'
const Button = styled.button`
padding: 32px;
`;
Tailwind + css-in-js
import 'twin.macro';
const Input = () => <input tw="border hover:border-black" />
// 조건부 tw
import tw from 'twin.macro';
const Input = ({ hasHover }) => (
<input css={[tw`border`, hasHover && tw`hover:border-black`]} />
);
// Styled Components
const Input = tw.input`border hover:border-black`;
const PurpleInput = tw(Input)`border-purple-500`;