首页 > 解决方案 > 如何将这两个较少的@Media 查询与“或”条件结合起来?

问题描述

假设我有一些这样的代码:

@desktop-min-width:         1024px;
@phone-max-width:           768px;

@desktop:          ~"only screen and (min-width: @{desktop-min-width})";
@tablet:           ~"only screen and (min-width: @{phone-max-width}) and (max-width: @{desktop-min-width})";
@phone:            ~"only screen and (max-width: @{phone-max-width})";

.hola {

  @phone {
    height: 100vh;
    top:    10px;
  }

  @tablet {
    height: 30vh;
    top:    30%;
  }

  @desktop {
    height: 30vh;
    top:    30%;
  }

}

// ...more styles...

我有办法将@tablet 和@desktop 结合起来并减少重复吗?这样的事情是我想象的:

@tablet or @desktop {
  height: 30vh;
  top:    30%;
}

标签: csssassresponsive-designlessmedia-queries

解决方案


只需使用逗号就可以满足您的要求:

@tablet, @desktop  {
  ...
}

推荐阅读