Reputation: 5169
Is it possible to calculate in media queries
when using SCSS
and a variable?
I would like to assign a value to a breakpoint variable and in some cases calculate + 1
directly in the media query SCSS
file like this:
$bp-xl: 1024px;
@media (min-width: $bp-xl + 1) { ... } /* MIN-WIDTH = 1025px */
So my new min-width would be 1025px
.
Upvotes: 6
Views: 4212
Reputation: 192
you can use calc(#{$bp-xl} + 1px);
. calc
does the calcuation, the #{}
is string interpolation, which lets you insert a variable into calc
Upvotes: 4
Reputation: 181
Yes, It's Possible! Have a look for Demo! https://codepen.io/navdeepsingh/pen/qpejKo
h1 {
font-size: 12px;
background: green;
color: white;
}
$bp-xl: 1024px;
@media (min-width: $bp-xl + 6) {
h1 {
font-size: 50px;
background: pink;
color: black;
}
} /* MIN-WIDTH = 1030px */
<h1>HELLO</h1>
Upvotes: 3