Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

提一个bug 关于存在@media后 生成的background-position属性并没有放到应该放到的@media里 导致图片只显示后者属性 #29

Open
w2230030100 opened this issue Sep 25, 2015 · 7 comments

Comments

@w2230030100
Copy link

比如我有如下代码

.bacpic(@w,@h,@url){
  width: @w;
  height: @h;
  background: url(@url) no-repeat;
}

header{
  @header-h:40px;

  @logo-w:178px;
  @logo-h:34px;
  @logo-url:"../images/j-t-logo.png?__sprite";
  @logo-ml:12px;
  @logo-mt:7px;

  @phone-mr:15px;

  height: @header-h;

  .logo{
    .bacpic(@logo-w,@logo-h,@logo-url);
    margin-left: @logo-ml;
    margin-top: @logo-mt;
  }

  .phone{
    float: right;
    margin-right: @phone-mr;
    .ui-font(1.4rem,#00549d,@header-h);
  }

  @media @medium-up {
    height: 2*@header-h;

    .logo{
      .bacpic(2*@logo-w,2*@logo-h,"../images/j-t-logo@2x.png?__sprite");

      margin-left: 2*@logo-ml;
      margin-top: 2*@logo-mt;
    }
    .phone{
      margin-right: 2*@phone-mr;
    }
  }
}

当雪碧图处理之后

header {
  height: 40px;
}

header .logo {
  width: 178px;
  height: 34px;

  margin-left: 12px;
  margin-top: 7px;
  background-repeat: no-repeat;
}

header .phone {
  float: right;
  margin-right: 15px;
  font: normal 1.4rem/40px "Microsoft Yahei";
  color: #00549d;
}

@media only screen and (min-width: 641px) {
  header {
    height: 80px;
  }

  header .logo {
    width: 356px;
    height: 68px;

    margin-left: 24px;
    margin-top: 14px;
    background-repeat: no-repeat;
  }

  header .phone {
    margin-right: 30px;
  }
}
//这个位置的属性 start 这里被放到@media的外边了 且后者覆盖了前者的设置
header .logo {
  background-position: -178.5px 0px
}

header .logo {
  background-position: 0px -36px
}
//这个位置的属性 end
header .logo {
  background-size: 357px 105px;
  background-image: url(../images/common_0.5_z.png)
}

其中@media对屏幕自适应宽度的设置并没有被引用进来 导致屏幕变化后只应用logo后者的background-position设置

如果改成如下代码 显示则正常了

header {
  height: 40px;
}

header .logo {
  width: 178px;
  height: 34px;

  margin-left: 12px;
  margin-top: 7px;
  background-repeat: no-repeat;
}

header .phone {
  float: right;
  margin-right: 15px;
  font: normal 1.4rem/40px "Microsoft Yahei";
  color: #00549d;
}
////////如果是background-position在这里就正确了
header .logo {
  background-position: -178.5px 0px
}
@media only screen and (min-width: 641px) {
  header {
    height: 80px;
  }

  header .logo {
    width: 356px;
    height: 68px;

    margin-left: 24px;
    margin-top: 14px;
    background-repeat: no-repeat;
  }
 ////////如果是background-position在这里就正确了
  header .logo {
    background-position: 0px -36px
  }

  header .phone {
    margin-right: 30px;
  }
}




header .logo {
  background-size: 357px 105px;
  background-image: url(../images/common_0.5_z.png)
}
@w2230030100
Copy link
Author

大神们都很忙 没人理我么😭

@oxUnd
Copy link
Contributor

oxUnd commented Oct 12, 2015

这个不好办,因为如果考虑 media 就得知道 css 执行的上下文,这会导致静态工具处理太复杂;当然可以再引入更多的一些 标识 来实现这类功能,后续调研看是否合适引入此类功能。

@mudoo
Copy link

mudoo commented Mar 21, 2016

@xiangshouding
mudoo@009a93d
项目中要这样处理,所以根据processInline思路,将@media拆分大概实现了下,不晓得会不会有问题...后续有问题再来补充

@oxUnd
Copy link
Contributor

oxUnd commented Mar 21, 2016

@mudoo 其实 media 蛮复杂的一种情况,只能局部解决部分情况吧;我看要不要引入一个全面支持版本,以及保留一个性能版本。

@hxlniada
Copy link

请问这个bug怎么样了?现在我们是在retina屏幕下使用二倍图,那这样就不能跟雪碧图结合了啊,怎么搞

@hxlniada
Copy link

😭有没有大神帮解决这个问题啊。。。太需要了

@mudoo
Copy link

mudoo commented Jan 10, 2017

@hxlniada https://github.com/mudoo/fis-spriter-csssprites-group
目前自用,分media处理雪碧图,可能还有不完善的地方,你可以先试试看有没问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants