// .sass
$font-stack: Helvetica, sans-serif
$primary-color: #333
body
font: 100% $font-stack
color: $primary-folor
//.scss
$font-stack: Helvetica, sans-serif;
$primary-color: #333;
body {
font: 100% $font-stack;
color: $primary-folor;
}
CSSMoudle.module.css
.wrapper{
background: black;
padding:1rem;
color:white;
font-size: 2rem;
}
.inverted{
color:black;
background: white;
border:1px solid black;
}
/* 글로벌 css 를 작성하고 싶다면 */
:global .something{
font-weight: 800;
color:aqua;
}
CSSMoudle.js
import React from 'react'
import styles from './CSSModule.module.css'
const CSSModule = () =>{
return (
<div className={$styles.wrapper}>
Hi, My name is <span className="something">jinseong</span>
</div>
)
}
export default CSSModule
console.log(styles)
import React from "react";
import styled, { css } from "styled-components";
const sizes = {
desktop: 1024,
tablet: 768,
};
const media = Object.keys(sizes).reduce((acc, label) => {
acc[label] = (...args) => css`
@media (max-width: ${sizes[label] / 16}em) {
${css(...args)};
}
`;
return acc;
}, {});
const Box = styled.div`
/* props로 넣어 준 값을 직접 전달해 줄 수 있다 */
background: ${(props) => props.color || "blue"};
padding: 1rem;
display: flex;
width: 1024px;
margin: 0 auto;
${media.desktop`width: 768px`}
${media.tablet`width:100%`}
`;
/* @media (max-width: 1024px) {
width: 768px;
}
@media (max-width: 768px) {
width: 100%;
} */
const Button = styled.button`
background: white;
color: black;
border-radius: 4px;
padding: 0.5rem;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
font-size: 1rem;
font-weight: 600;
/* & 문자를 사용하여 Sass처럼 자기 자신 선택 가능 */
&:hover {
background: rgba(255, 255, 255, 0.9);
}
/* 다음 코드는 inverted 값이 true일 때 특정 스타일을 부여해 줍니다 */
${(props) =>
props.inverted &&
css`
background: none;
border: 2px solid white;
color: white;
&:hover {
background: white;
color: black;
}
`}
& + button {
margin-left: 1rem;
}
`;
export default function StyledComponent() {
return (
<Box color="black">
<Button>Hi</Button>
<Button inverted={true}>Only Outline</Button>
</Box>
);
}