Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 4 - how to use media query mixin

Tags:

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.

like image 235
user1678736 Avatar asked Sep 13 '15 01:09

user1678736


People also ask

How do I use Bootstrap 4 media query mixins?

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 . Show activity on this post. Show activity on this post.

Can we use media query with Bootstrap?

Since Bootstrap is developed to be mobile first, we use a handful of media queries to create sensible breakpoints for our layouts and interfaces. These breakpoints are mostly based on minimum viewport widths and allow us to scale up elements as the viewport changes.


1 Answers

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.

like image 188
Edward Avatar answered Sep 20 '22 19:09

Edward