๐ฎ BootStrap5 ๋ฐ์ํ ์์คํ - ์ค๋จ์ (๋ฏธ๋์ด ์ฟผ๋ฆฌ)
์ค๋จ์ Breakpoints
Breakpoints๋ Bootstrap์ ๋ฐ์ํ ๋ ์ด์์์ด ๋ทฐํฌํธ ํฌ๊ธฐ ๋๋ ๊ธฐ๊ธฐ์์ ์ด๋ป๊ฒ ์๋ ํ ์ง ๊ฒฐ์ ํ๋ ์ฌ์ฉ์๊ฐ ์ ์ ๊ฐ๋ฅํ ๋์ด์ ๋๋ค.
Bootstrap์๋ ๋ฐ์ํ ์ ์์ ์ํด grid tiers ๋ผ๊ณ ํ๋ 6๊ฐ์ Breakpoints๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.
์ด๋ฌํ breakpoints๋ Sass ์์ค ํ์ผ์ ์ฌ์ฉํ ๊ฒฝ์ฐ ์ฌ์ฉ์๊ฐ ์ง์ ํ ์ ์์ต๋๋ค.
Breakpoint | Class infix | Dimensions |
X-Small | None | <576px |
Small | sm | ≥576px |
Medium | md | ≥768px |
Large | lg | ≥992px |
Extra large | xl | ≥1200px |
Extra extra large | xxl | ≥1400px |
์ค๋จ์ ์ Sass๋ฅผ ํตํด ์ฌ์ฉ์ ์ ์ ํ ์ ์์ต๋๋ค.
_variables.scss ์คํ์ผ ์ํธ์ Sass ๋งต์์ ์ฐพ์ ์ ์์ต๋๋ค.
$grid-breakpoints: (
xs: 0,
sm: 576px,
md: 768px,
lg: 992px,
xl: 1200px,
xxl: 1400px
);
๋ฏธ๋์ด ์ฟผ๋ฆฌ
Bootstrap์ ๋ชจ๋ฐ์ผ ์ฐ์ ์ผ๋ก ๊ฐ๋ฐ ๋์์ผ๋ฏ๋ก ๋ช ๊ฐ์ง ๋ฏธ๋์ด ์ฟผ๋ฆฌ๋ฅผ ์ด์ฉํ์ฌ ๋ ์ด์์์ ์ ํฉํ breakpoints๋ฅผ ๋ง๋ญ๋๋ค.
Min-width
// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) { ... }
// Medium devices (tablets, 768px and up)
@media (min-width: 768px) { ... }
// Large devices (desktops, 992px and up)
@media (min-width: 992px) { ... }
// X-Large devices (large desktops, 1200px and up)
@media (min-width: 1200px) { ... }
// XX-Large devices (larger desktops, 1400px and up)
@media (min-width: 1400px) { ... }
๊ธฐ์กด ๋ฏธ๋์ด ์ฟผ๋ฆฌ๋ ์ด๋ ๊ฒ ํ๋ํ๋ ์ ํด์ ์จ์คฌ์์ต๋๋ค.
ํ์ง๋ง ๋ถํธ์คํธ๋ฉ์์ ์ด๊ฒ๋ค์ ๋ชจ๋ํํ์ฌ ์ง์ํด์ค๋๋ค.
/* No media query necessary for xs breakpoint as it's effectively `@media (min-width: 0) { ... } */`
@include media-breakpoint-up(sm) { ... }
@include media-breakpoint-up(md) { ... }
@include media-breakpoint-up(lg) { ... }
@include media-breakpoint-up(xl) { ... }
@include media-breakpoint-up(xxl) { ... }
/* Example: Hide starting at `min-width: 0`, and then show at the `sm` breakpoint */
.custom-class {
display: none;
}
@include media-breakpoint-up(sm) {
.custom-class {
display: block;
}
}
Max-width
/* ๋ถํธ์คํธ๋ฉ */
@include media-breakpoint-down(sm) { ... }
@include media-breakpoint-down(md) { ... }
@include media-breakpoint-down(lg) { ... }
@include media-breakpoint-down(xl) { ... }
@include media-breakpoint-down(xxl) { ... }
@include media-breakpoint-down(md) {
.custom-class {
display: block;
}
}
/*----------------------------------------*/
/* css */
// X-Small devices (portrait phones, less than 576px)
@media (max-width: 575.98px) { ... }
// Small devices (landscape phones, less than 768px)
@media (max-width: 767.98px) { ... }
// Medium devices (tablets, less than 992px)
@media (max-width: 991.98px) { ... }
// Large devices (desktops, less than 1200px)
@media (max-width: 1199.98px) { ... }
// X-Large devices (large desktops, less than 1400px)
@media (max-width: 1399.98px) { ... }
๋จ์ผ ์ค๋จ์
/* ๋ถํธ์คํธ๋ฉ */
@include media-breakpoint-only(xs) { ... }
@include media-breakpoint-only(sm) { ... }
@include media-breakpoint-only(md) { ... }
@include media-breakpoint-only(lg) { ... }
@include media-breakpoint-only(xl) { ... }
@include media-breakpoint-only(xxl) { ... }
/*----------------------------------------*/
/* css */
@media (min-width: 768px) and (max-width: 991.98px) { ... }
์ค๋จ์ ์ฌ์ด
/* ๋ถํธ์คํธ๋ฉ */
@include media-breakpoint-between(md, xl) { ... }
/*----------------------------------------*/
/* css */
@media (min-width: 768px) and (max-width: 1199.98px) { ... }
# Reference
https://getbootstrap.kr/docs/5.0/layout/breakpoints/