Style Sheet/Bootstrap5

๐Ÿ”ฎ BootStrap5 ๋ฐ˜์‘ํ˜• ์‹œ์Šคํ…œ - ์ปจํ…Œ์ด๋„ˆ

์ธํŒŒ_ 2021. 10. 15. 18:20

๋ถ€ํŠธ์ŠคํŠธ๋žฉ-์ปจํ…Œ์ด๋„ˆ

์ปจํ…Œ์ด๋„ˆ(Container)

์ปจํ…Œ์ด๋„ˆ๋Š” Bootstrap์—์„œ ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ ๋ ˆ์ด์•„์›ƒ ์š”์†Œ์ด๋ฉฐ ๊ธฐ๋ณธ ๊ทธ๋ฆฌ๋“œ ์‹œ์Šคํ…œ์„ ์‚ฌ์šฉํ•  ๋•Œ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

์ปจํ…Œ์ด๋„ˆ๋Š” ๋‚ด์šฉ์„ ํฌํ•จํ•˜๊ณ  ์ฑ„์šฐ๊ณ  (๋•Œ๋กœ๋Š”) ๋‚ด์šฉ์„ ์ค‘์•™ ์ •๋ ฌํ•˜๋Š” ๋ฐ์— ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

 

Bootstrap์—๋Š” ์„ธ ๊ฐ€์ง€ ๋‹ค๋ฅธ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค:

  • ๊ฐ ๋ฐ˜์‘ํ˜• ์ค‘๋‹จ์ ์— max-width๋ฅผ ์„ค์ •ํ•˜๋Š” .container
  • ๋ชจ๋“  ์ค‘๋‹จ์ ์— width: 100%๋ฅผ ์„ค์ •ํ•˜๋Š” .container-fluid
  • ์ •์˜๋œ ์ค‘๋‹จ์ ๊นŒ์ง€ width: 100%๋ฅผ ์„ค์ •ํ•˜๋Š” .container-{breakpoint}

๋ถ€ํŠธ์ŠคํŠธ๋žฉ-์ปจํ…Œ์ด๋„ˆ

 

์•„๋ž˜ ํ‘œ๋Š” ๊ฐ ์ค‘๋‹จ์ ์—์„œ ๊ฐ ์ปจํ…Œ์ด๋„ˆ์˜ max-width๊ฐ€ ์›๋ž˜ .container์™€ ‘.container-fluid’๊ฐ€ ์–ด๋–ป๊ฒŒ ๋น„๊ต๋˜๋Š”์ง€ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

๋ถ€ํŠธ์ŠคํŠธ๋žฉ-์ปจํ…Œ์ด๋„ˆ


๋ธŒ๋ผ์šฐ์ € ๋ฐ˜์‘ํ˜• ์ปจํ…Œ์ด๋„ˆ ์˜ˆ์‹œ

์•„๋ž˜ ๋งํฌ ํ™ˆํŽ˜์ด์ง€์— ๋“ค์–ด๊ฐ€์„œ ์ง์ ‘ ๋ธŒ๋ผ์šฐ์ € ๊ฐ€๋กœ ๊ธธ์ด๋ฅผ ์ค„์—ฌ๋ณด๋ฉด ๋™์ž‘์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

Grid Template · Bootstrap v5.0

Containers Additional classes added in Bootstrap v4.4 allow containers that are 100% wide until a particular breakpoint. v5 adds a new xxl breakpoint.

getbootstrap.kr

๋ธŒ๋ผ์šฐ์ € ๋ฐ˜์‘ํ˜• ์ปจํ…Œ์ด๋„ˆ ์˜ˆ์‹œ

 

๊ธฐ๋ณธ ์ปจํ…Œ์ด๋„ˆ

๊ธฐ๋ณธ .container ํด๋ž˜์Šค๋Š” ๋ฐ˜์‘ํ˜• ๊ณ ์ • ๋„ˆ๋น„ ์ปจํ…Œ์ด๋„ˆ์ž…๋‹ˆ๋‹ค.

์ฆ‰, max-width๊ฐ€ ๊ฐ ์ค‘๋‹จ์ ์—์„œ ๋ณ€๊ฒฝ๋ฉ๋‹ˆ๋‹ค.

<div class="container">
  <!-- Content here -->
</div>

 

๋ฐ˜์‘ํ˜• ์ปจํ…Œ์ด๋„ˆ

๋ฐ˜์‘ํ˜• ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ง€์ •๋œ ์ค‘๋‹จ์ ์— ๋„๋‹ฌํ•  ๋•Œ๊นŒ์ง€ ๋„ˆ๋น„๊ฐ€ 100%์ธ ํด๋ž˜์Šค๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๊ทธ ์ดํ›„์—๋Š” ๋” ๋†’์€ ๊ฐ ์ค‘๋‹จ์ ์— ๋Œ€ํ•ด max-width๋ฅผ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, .container-sm์€ md, lg, xl ๋ฐ xxl๋กœ ํ™•์žฅ๋˜๋Š” sm ์ค‘๋‹จ์ ์— ๋„๋‹ฌํ•  ๋•Œ๊นŒ์ง€ ์‹œ์ž‘ํ•˜๋Š” ๋„ˆ๋น„๊ฐ€ 100%์ž…๋‹ˆ๋‹ค.

<div class="container-sm">100% wide until small breakpoint</div>
<div class="container-md">100% wide until medium breakpoint</div>
<div class="container-lg">100% wide until large breakpoint</div>
<div class="container-xl">100% wide until extra large breakpoint</div>
<div class="container-xxl">100% wide until extra extra large breakpoint</div>

 

์œ ๋™ ์ปจํ…Œ์ด๋„ˆ

๋ทฐํฌํŠธ์˜ ์ „์ฒด ๋„ˆ๋น„์— ๊ฑธ์ณ ์žˆ๋Š” ์ „์ฒด ๋„ˆ๋น„ ์ปจํ…Œ์ด๋„ˆ์— .container-fluid๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

<div class="container-fluid">
  ...
</div>

 

Sass

์œ„์— ๋‚˜์™€์žˆ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ Bootstrap์€ ์›ํ•˜๋Š” ๋ ˆ์ด์•„์›ƒ์„ ๋นŒ๋“œํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋˜๋Š” ์ผ๋ จ์˜ ๋ฏธ๋ฆฌ ์ •์˜๋œ ์ปจํ…Œ์ด๋„ˆ ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ฏธ๋ฆฌ ์ •์˜๋œ ์ปจํ…Œ์ด๋„ˆ ํด๋ž˜์Šค๋ฅผ ๊ฐ•ํ™”ํ•˜๋Š” Sass ๋งต(_variables.scss์— ์žˆ์Œ)์„ ์ˆ˜์ •ํ•˜์—ฌ ์‚ฌ์šฉ์ž ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

$container-max-widths: (
  sm: 540px,
  md: 720px,
  lg: 960px,
  xl: 1140px,
  xxl: 1320px
);

Sass๋ฅผ ์‚ฌ์šฉ์ž ์ง€์ •ํ•˜๋Š” ๊ฒƒ ์™ธ์—๋„ Sass ๋ฏน์Šค์ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ณ ์œ ํ•œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋งŒ๋“ค ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

/* Source mixin */
@mixin make-container($padding-x: $container-padding-x) {
  width: 100%;
  padding-right: $padding-x;
  padding-left: $padding-x;
  margin-right: auto;
  margin-left: auto;
}

/* Usage */
.custom-container {
  @include make-container();
}

# Reference

https://getbootstrap.kr/docs/5.0/layout/containers/