简体   繁体   English

如何在 angular 组件的styles.scss 中使用媒体查询?

[英]How to use media queries in angular component's styles.scss?

I am trying to use media query in component's styles, but when I resize the window, nothing is happens我试图在组件的样式中使用媒体查询,但是当我调整窗口大小时,没有任何反应

 @media query screen and (max-width: 768px) { 
/* Here are some changes*/
}

It doesn't work at all, do I need to load some modules or how to fix it.它根本不起作用,我是否需要加载一些模块或如何修复它。 Any help appreciate.任何帮助表示赞赏。

Use following syntax.使用以下语法。 This is the correct syntax for media query.这是媒体查询的正确语法。 Hope this helps!!希望这可以帮助!!

@media only screen and (max-width: 768px) { 
    /* Here are some changes*/
}

remove query删除query

@media screen and (max-width: 768px) 
{
 /* Here are some changes*/
}

You might want to write different media queries for each breakpoint.您可能希望为每个断点编写不同的媒体查询。 Also, the syntax is like below此外,语法如下

    /* Tablet*/
    @media screen and (max-width: 768px) {
      /* Here are some changes*/
    }

   /* Mobile */
    @media screen and (max-width: 320px) {
          /* Here are some changes*/
    }

A bit simpler way,更简单的方法,

@media (max-width: 768px) { 
    /* Here are some changes*/
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM