Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using media breakpoints in Bootstrap 4 / SASS - _breakpoints.scss does not know $grid-breakpoints

I am trying to use media queries in Bootstrap 4.

On their website they do this:

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

// Example usage:
@include media-breakpoint-up(sm) {
  .some-class {
    display: block;
  }
}

So I grabbed the Bootstrap SCSS, and copied the _breakpoints.scss and included this in my project. I import it, and then try to use a media query:

@import "partials/breakpoints";

@include media-breakpoint-up(sm) {

  .mycontainer  {
    background-color: black;
  }
}

However, I get the following error when i compile SASS:

Change detected to: main.scss error pages/_geschichte.scss (Line 54: Undefined variable: "$grid-breakpoints".)

Am I doing this the wrong way or will I need to include more files? I then tried to fix that by also including _grid.scss, but then for this, something else is required again, so I got unsure whether this is indeed the right way and thought I'd better ask.

like image 903
George Welder Avatar asked Jun 19 '17 08:06

George Welder


People also ask

Does Bootstrap 4 support Sass and Flexbox?

From the get-go, Bootstrap is SASS only. This may sound like bad news, but the CSS community has rallied around SASS over LESS for the last few years. By creating a single SASS-based codebase, this means developers can focus on only one branch of the framework.

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 ...

What does @media do in SCSS?

The @media rule is used in media queries to apply different styles for different media types/devices. Media queries can be used to check many things, such as: width and height of the viewport. width and height of the device.


1 Answers

Did you include the bootstrap variables.scss ? Seems like the variables are missing

like image 120
Bart de Bruin Avatar answered Sep 28 '22 09:09

Bart de Bruin