💻 들어가며
프리온보딩 과제를 복습하면서 style-components와 react-router-dom으로
레이아웃을 그리면서 발생한 문제를 해결한 포스팅입니다.
❌ 에러
const SidebarContainer = styled.div`
width: 300px;
height: 100vh;
background-color: #657c65;
`;
위 코드처럼 별도로 margin 이나 padding 없어도
자동으로 여백이 생김
⚠️ 에러 원인 ?
The default box sizing is content-box, which means padding and borders are added to the overall box.
출처 : Learn CSS! (https://web.dev/learn/css/box-model/)
box-sizing의 디폴트 값은 content box입니다.
따라서 padding box와 boder box 때문에 여백이 생깁니다.
✅ 에러 해결
// src/styles/GlobalStyle.ts
import { createGlobalStyle } from "styled-components";
const GlobalStyle = createGlobalStyle`
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
`;
GlobalStyles에 margin, padding 0
box-sizing: border-box 설정을 함으로써 해결할 수 있습니다
🙇♂️ 참고자료
- box-sizing
- styled-components - createGlobalStyle
'Devlog(개발회고) > 레딧 클론' 카테고리의 다른 글
[레딧 클론] 커뮤니티 생성 페이지 구현 (0) | 2022.12.19 |
---|---|
[레딧 클론] 프로젝트 재개 - 로그인 / 회원가입 기능 구현 (0) | 2022.12.18 |