Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
829 views
in Technique[技术] by (71.8m points)

sass - Bootstrap 4 - how to use media query mixin

How do I set a media breakpoint let's say from medium to large - do I nest the min mixin and max mixin or how do I do that.

the output I'm after is something like this: @media (min-width: 480px) and (max-width: 767px) using the breakpoint mixin.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use media-breakpoint-between($lower, $upper)

Dependencies

The mixins are declared in mixins/_breakpoints.scss, and depend on the $grid-breakpoints map, found in _variables.scss.

Example

Breakpoint map:

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

Mixin:

@include media-breakpoint-between(sm, md) {
    // your code
}

Compiles to

@media (min-width: 576px) and (max-width: 991px) {}

Important notice

Media-breakpoint-between mixin uses 'lower' and 'upper' values of declared breakpoint.

  • The 'lower' value of breakpoint is the declared value in $grid-breakpoint map.

  • The 'upper' value of specific breakpoint is equal to the value of higher breakpoint minus 1px.

Upper & lower breakpoint values example (based od $grid-breakpoint map)

Lower value of md is equal to 576
Upper value of md is equal to 991 ( value of next breakpoint (lg) minus 1px (992px-1px)

Other media mixins

@include media-breakpoint-up(sm) {} creates a breakpoint with a min-width of $sm.

@include media-breakpoint-down(md) {} creates a breakpoint with a max-width of $md.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...