0

I want to add class depending on a flag and the screen resolution I tried

[ngClass]="singleFloorFlagStyle ? 'floorPlanContainerWidth' : 'singleFloor'"

 @media only screen and (min-width: 1500){
.floorPlanContainerWidth{
 width: 670px;
 }
}

 @media only screen and (max-width: 1400){
.floorPlanContainerWidth{
width: 613px !important;
}
}

.singleFloor{
width: 1300px;
}

singleFloorFlagStyle I would receive as true or false. So singleFloor class gets applied but floorPlanContainerWidth class doesn't.How can I make the media query classes work.

I had referred this Angular 5: Use ngClass to switch classes for mobile and desktop views but I guess my scenario is different

Enthu
  • 512
  • 2
  • 13
  • 38
  • Is your problem that the class itself is never applied or that the style of the class isn't applied? Because right now you have a "dead range" of 100px between 1400 and 1500 where no style will be applied for the `floorPlanContainerWidth` class. – Chrillewoodz Oct 21 '19 at 11:46
  • @Chrillewoodz The class itself doesn't get applied ,thanks – Enthu Oct 21 '19 at 11:49
  • .. and you are sure `singleFloorFlagStyle` is true? – Chrillewoodz Oct 21 '19 at 11:51
  • Yeah :) because singleFloor class gets applied, so flag is working – Enthu Oct 21 '19 at 11:52

2 Answers2

1

You have not added px so floorPlanContainerWidth not applying

 @media only screen and (min-width: 1500px){
   .floorPlanContainerWidth{
     width: 670px;
   }
 }

 @media only screen and (max-width: 1400px){
   .floorPlanContainerWidth{
      width: 613px !important;
   }
 }

.singleFloor{
   width: 1300px;
}
Hiren Vaghasiya
  • 5,454
  • 1
  • 11
  • 25
0

Try this

[ngClass]="{'floorPlanContainerWidth' : singleFloorFlagStyle , 'singleFloor' : !singleFloorFlagStyle }"

If you want to set an initial size of the floorPlanConatainerWidth. So that even if it is not in the media queries ratio then also style will be applied. Then you have to add the class outside the media queries also and define some width there

.floorPlanConatainerWidth{
  // Initially set width without media queries
}

@media ...

Hitech Hitesh
  • 1,641
  • 1
  • 9
  • 18