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.
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.
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 ...
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.
Did you include the bootstrap variables.scss ? Seems like the variables are missing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With