Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using media breakpoints in Bootstrap 4-alpha

In Bootstrap 3 I use this:

.something {     padding: 5px;     @media screen and (min-width: $screen-sm-min) {          padding: 20px;     }     @media screen and (min-width: $screen-md-min) {          padding: 40px;     } } 

How can I do the same thing in Boostrap 4-alpha? I can't find an example in their docs. This is in variables.scss

$grid-breakpoints: (   xs: 0,   sm: 576px,   md: 768px,   lg: 992px,   xl: 1200px ) !default; @include _assert-ascending($grid-breakpoints, "$grid-breakpoints"); @include _assert-starts-at-zero($grid-breakpoints); 
like image 801
Ivan Topić Avatar asked Jan 17 '17 13:01

Ivan Topić


People also ask

How do I use media queries in Bootstrap 4?

The general syntax of the media queries in the Bootstrap framework is @media (min-width: ~ breakpoint in pixels here ~) ~ some CSS rules to be applied ~ which narrows the CSS rules defined down to a specific viewport size but eventually the opposite query might be used like @media (max-width: ~ breakpoint in pixels ...

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.

What is Bootstrap 4’s new breakpoint?

Bootstrap 4 introduced a new breakpoint to the grid system XL. Below are the Bootstrap 4 media queries used for the grid system breakpoints for you to add to your project’s CSS file to customize things. If you are new to the Bootstrap 4 grid I wrote a post explaining how it works in this post.

What are the different media query ranges in Bootstrap?

Media queries 1 Min-width. Bootstrap primarily uses the following media query ranges—or breakpoints—in our source Sass files for our layout, grid system, and components. 2 Max-width. These mixins take those declared breakpoints, subtract .02px from them, and use them as our max-width values. 3 Single breakpoint. ... 4 Between breakpoints

What is Bootstrap 4 media objects?

Bootstrap 4 Media Objects. ❮ Previous Next ❯. Bootstrap provides an easy way to align media objects (like images or videos) together with content. Media objects are often used to display blog comments, tweets and so on: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

How to use bootstrap media breakpoints in module level stylesheet?

In addition to the above, if you want to use the bootstrap media breakpoints in module level stylesheets (for example in create-react-app components), by default they will be undefined and you'll need to import the mixins and its dependencies separately into each module.


2 Answers

Update: Bootstrap 5.

v5 breakpoints reference


Original answer: Use breakpoint mixins like this:

.something {     padding: 5px;     @include media-breakpoint-up(sm) {          padding: 20px;     }     @include media-breakpoint-up(md) {          padding: 40px;     } } 

v4 breakpoints reference

v4 alpha6 breakpoints reference


Below full options and values.

Breakpoint & up (toggle on value and above):

@include media-breakpoint-up(xs) { ... } @include media-breakpoint-up(sm) { ... } @include media-breakpoint-up(md) { ... } @include media-breakpoint-up(lg) { ... } @include media-breakpoint-up(xl) { ... } 

breakpoint & up values:

// Extra small devices (portrait phones, less than 576px) // No media query 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) { ... }  // Extra large devices (large desktops, 1200px and up) @media (min-width: 1200px) { ... } 

breakpoint & down (toggle on value and down):

@include media-breakpoint-down(xs) { ... } @include media-breakpoint-down(sm) { ... } @include media-breakpoint-down(md) { ... } @include media-breakpoint-down(lg) { ... } 

breakpoint & down values:

// Extra small devices (portrait phones, less than 576px) @media (max-width: 575px) { ... }  // Small devices (landscape phones, less than 768px) @media (max-width: 767px) { ... }  // Medium devices (tablets, less than 992px) @media (max-width: 991px) { ... }  // Large devices (desktops, less than 1200px) @media (max-width: 1199px) { ... }  // Extra large devices (large desktops) // No media query since the extra-large breakpoint has no upper bound on its width 

breakpoint only:

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

breakpoint only values (toggle in between values only):

// Extra small devices (portrait phones, less than 576px) @media (max-width: 575px) { ... }  // Small devices (landscape phones, 576px and up) @media (min-width: 576px) and (max-width: 767px) { ... }  // Medium devices (tablets, 768px and up) @media (min-width: 768px) and (max-width: 991px) { ... }  // Large devices (desktops, 992px and up) @media (min-width: 992px) and (max-width: 1199px) { ... }  // Extra large devices (large desktops, 1200px and up) @media (min-width: 1200px) { ... } 
like image 135
Syden Avatar answered Oct 26 '22 05:10

Syden


I answered a similar question here

As @Syden said, the mixins will work. Another option is using SASS map-get like this..

@media (min-width: map-get($grid-breakpoints, sm)){   .something {     padding: 10px;    } }  @media (min-width: map-get($grid-breakpoints, md)){   .something {     padding: 20px;    } } 

http://www.codeply.com/go/0TU586QNlV


Bootstrap 4 Breakpoints demo

like image 39
Zim Avatar answered Oct 26 '22 05:10

Zim