When using Angular2 2.4.3 in combination with CSS3 media query features either:
or
the html component in both cases is not formatted according to the media query specifications. Instead, only the non-media-query CSS parts are rendered.
import {Component} from '@angular/core';
@Component({
/* necessary for using relative paths (only works in combination with
* 'commonjs'-transpiled modules, see:
* https://angular.io/docs/ts/latest/cookbook/component-relative-paths.html
*/
moduleId: module.id,
selector: 'login',
templateUrl: '../templates/login.component.html',
styles: [`
@media only screen and (min-width: 840px)
.layout {
font-size: 58px;
}
.layout { background: green; }
`]
})
export class LoginComponent {
}
Hint: for sure, I'm using a desktop monitor with a width-resolution >840px ;)
Am I doing something wrong or are media queries not yet supported by Angular2? Maybe, I have to do additional stuff to let Angular2 detect the used media correctly?
@Holger, the problem is not with Angular but in your style implementation. You have omitted curly brackets around the styles within your media query. It should look like below and I think it should solve your problem.
styles: [`
@media only screen and (min-width: 840px) {
.layout {
width: 368px;
}
}
.layout { background: green; }
`]
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