Hla mus rau cov ntsiab lus tseem ceeb Hla mus rau docs navigation
Check
in English

Breakpoints

Breakpoints yog customizable dav uas txiav txim siab seb koj qhov kev teeb tsa kev ua haujlwm zoo li cas hla cov khoom siv lossis qhov chaw saib qhov loj me hauv Bootstrap.

Cov ntsiab lus tseem ceeb

  • Breakpoints yog lub tsev thaiv ntawm kev tsim qauv. Siv lawv los tswj thaum koj qhov layout tuaj yeem hloov kho ntawm ib qho chaw saib lossis qhov loj me.

  • Siv cov lus nug xov xwm los tsim kho koj li CSS los ntawm kev tawg. Media queries yog ib tug feature ntawm CSS uas tso cai rau koj mus conditionally siv style raws li ib tug txheej ntawm browser thiab operating system tsis. Peb feem ntau siv min-widthhauv peb cov lus nug xov xwm.

  • Mobile ua ntej, teb tsim yog lub hom phiaj. Bootstrap's CSS lub hom phiaj siv qhov tsawg kawg nkaus ntawm cov qauv los ua ib qho kev teeb tsa ua haujlwm ntawm qhov chaw me me, thiab tom qab ntawd muab cov khaubncaws sab nraud povtseg los kho cov qauv tsim rau cov khoom siv loj. Qhov no ua kom zoo rau koj CSS, txhim kho lub sijhawm ua haujlwm, thiab muab kev paub zoo rau koj cov neeg tuaj saib.

Muaj breakpoints

Bootstrap suav nrog rau 6 qhov kev ua txhaum cai, qee zaum hu ua kab sib chaws , rau lub tsev teb. Cov breakpoints no tuaj yeem kho tau yog tias koj siv peb cov ntaub ntawv Sass.

Breakpoint Chav kawm infix Qhov ntev
Ntxiv me me Tsis muaj <576 px
Me me sm ≥ 576 px
Nruab nrab md ≥ 768px
Loj lg ≥ 992 px
Ntxiv loj xl ≥1200px
Ntxiv loj loj xxl ≥ 1400 px

Txhua qhov chaw tawg tau raug xaiv los tuav cov thawv uas nws qhov dav yog qhov sib npaug ntawm 12. Breakpoints kuj yog tus sawv cev ntawm cov khoom siv sib txawv thiab qhov ntev ntawm qhov pom-lawv tsis tau tshwj xeeb rau txhua qhov kev siv lossis khoom siv. Hloov chaw, cov kab no muab lub hauv paus muaj zog thiab zoo ib yam los tsim rau ze li ntawm txhua yam khoom siv.

Cov breakpoints no yog customizable ntawm Sass-koj yuav pom lawv nyob rau hauv Sass daim ntawv qhia nyob rau hauv peb _variables.scssstylesheet.

$grid-breakpoints: (
  xs: 0,
  sm: 576px,
  md: 768px,
  lg: 992px,
  xl: 1200px,
  xxl: 1400px
);

Yog xav paub ntxiv thiab piv txwv txog kev hloov kho peb Sass maps thiab variables, thov mus saib ntawm Sass seem ntawm daim phiaj ntaub ntawv .

Media lus nug

Txij li thaum Bootstrap yog tsim los ua mobile ua ntej, peb siv ib tug puv tes ntawm xov xwm queries los tsim kom paub meej breakpoints rau peb layouts thiab interfaces. Cov breakpoints no feem ntau yog raws li qhov tsawg kawg nkaus saib qhov dav dav thiab tso cai rau peb los ntsuas cov ntsiab lus raws li qhov pom qhov hloov pauv.

Min-dav

Bootstrap feem ntau siv cov lus nug hauv qab no - lossis cov ntsiab lus tawg - hauv peb cov ntaub ntawv Sass rau peb qhov kev teeb tsa, kab sib chaws, thiab cov khoom.

// Source mixins

// 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) { ... }

// Usage

// 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;
  }
}

Cov Sass mixins no txhais nyob rau hauv peb CSS compiled siv qhov tseem ceeb tshaj tawm nyob rau hauv peb Sass variables. Piv txwv li:

// X-Small devices (portrait phones, less than 576px)
// No media query for `xs` since this is the default in Bootstrap

// 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) { ... }

Max dav

Peb qee zaus siv cov lus nug xov xwm uas mus rau lwm qhov kev taw qhia (qhov muab lub vijtsam loj lossis me dua ):

// No media query necessary for xs breakpoint as it's effectively `@media (max-width: 0) { ... }`
@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) { ... }

// Example: Style from medium breakpoint and down
@include media-breakpoint-down(md) {
  .custom-class {
    display: block;
  }
}

Cov mixins no coj cov lus tshaj tawm, rho tawm .02pxlos ntawm lawv, thiab siv lawv raws li peb max-widthqhov tseem ceeb. Piv txwv li:

// `xs` returns only a ruleset and no media query
// ... { ... }

// `sm` applies to x-small devices (portrait phones, less than 576px)
@media (max-width: 575.98px) { ... }

// `md` applies to small devices (landscape phones, less than 768px)
@media (max-width: 767.98px) { ... }

// `lg` applies to medium devices (tablets, less than 992px)
@media (max-width: 991.98px) { ... }

// `xl` applies to large devices (desktops, less than 1200px)
@media (max-width: 1199.98px) { ... }

// `xxl` applies to x-large devices (large desktops, less than 1400px)
@media (max-width: 1399.98px) { ... }
Vim li cas rho .02px? Browsers tam sim no tsis txhawb ntau cov ntsiab lus cov lus nug , yog li peb ua haujlwm nyob ib puag ncig cov kev txwv ntawm min-thiab max-ua ntej thiab cov chaw saib nrog feem ntau qhov dav (uas tuaj yeem tshwm sim nyob rau hauv qee yam ntawm cov khoom siv high-dpi, piv txwv li) los ntawm kev siv cov txiaj ntsig siab dua.

Ib qho tawg

Kuj tseem muaj cov lus nug xov xwm thiab cov mixins rau lub hom phiaj ib ntu ntawm qhov screen loj uas siv qhov tsawg kawg nkaus thiab qhov siab tshaj plaws breakpoint widths.

@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) { ... }

Piv txwv li, qhov @include media-breakpoint-only(md) { ... }yuav ua rau:

@media (min-width: 768px) and (max-width: 991.98px) { ... }

Nruab nrab ntawm cov ntsiab lus

Ib yam li ntawd, cov lus nug xov xwm tuaj yeem nthuav dav ntau qhov dav dav:

@include media-breakpoint-between(md, xl) { ... }

Qhov twg ua rau:

// Example
// Apply styles starting from medium devices and up to extra large devices
@media (min-width: 768px) and (max-width: 1199.98px) { ... }