In my angular application, I am writing scss for responsive design & I have few SASS variables declared outside & inside the media queries, but the variables declared inside the media query are not working.
In fonts.scss which is placed in 'styles' folder/directory (under src folder), I have few variables like this in mobile-first approach, I want to change the values of the variables in media queries as Iam working on a responsive design:
$font-1: normal normal normal 48px/48px Arial;
$font-2: normal normal 300 38px/38px Roboto;
@media screen and (min-width: 768px) {
$font-1: normal normal normal 56px/56px Arial;
$font-2: normal normal 300 48px/48px Roboto;
}
In my angular component's .scss file, I have included the scss file & I have some classes
@import 'fonts';
.title1 {
font: $font-1;
}
.title2 {
font: $font-2;
}
and in my component's .html file, I have this code.
<h1 class="title1">Title</h1>
<h2 class="title2">Sub-Title</h2>
In angular.json I have added this as I have .scss files in 'styles' folder/directory.
"stylePreprocessorOptions": {
"includePaths": [
"src/styles"
]
},
In index.html, I have added this in head section
<meta name="viewport" content="width=device-width, initial-scale=1" />
The problem I am facing is, the variables $font-1 and $font-2 are working but the values inside media queries are not working/reflecting. Any mistake I am doing here?
UPDATE: I even tried creating a mixin like this:
@mixin breakpoint($min-bp) {
@media (min-width: $min-bp) {
@content;
}
}
Included it in fonts.scss like this:
@include breakpoint('768px') {
$font-1: normal normal normal 56px/56px Arial;
$font-2: normal normal 300 48px/48px Roboto;
}
But still it did not work.