1

当屏幕尺寸大于 1024 像素时,我希望在我的网站背景中添加边框。

我在我的代码中使用了这个:

(max-width: 1024) { background-image: url("Gutter.png"), url(Background.png);
        background-position: left, center;
    }

但即使在大于 1024 像素的屏幕中,也只会出现背景。

4

3 回答 3

2

媒体查询的正确格式如下:

@media all and (max-width:1024px) {
    #selector {
        background-image: ...;
        background-position: ...;
    }
}
于 2013-08-14T14:36:08.233 回答
0
@media (max-width: 1024px) { 

#elementID { 
  background-image: url("Gutter.png");
  background-position: left, center; }

}
于 2013-08-14T14:36:38.770 回答
0

由于您的“边框”不是真正的边框,而是背景图像,因此您需要在媒体查询中重新定义背景(因为您不能只删除其中一个背景图像)。

http://cssdeck.com/labs/kfoaijgc

.foo {
    background: url(http://placekitten.com/300/400) center center no-repeat;
}

@media (min-width: 1025px) {
  .foo {
      background:
          url(http://placekitten.com/300/400) center center no-repeat,
          url(http://placekitten.com/100/100) repeat-y, /* left "border" */
          url(http://placekitten.com/100/100) top right repeat-y; /* right "border" */
  }
}

如果您使用的是真正的边框,那么解决方案会更简单:

.foo {
    /* no border here */
    background: url(http://placekitten.com/300/400) center center no-repeat;
}

@media (min-width: 1025px) {
  .foo {
      border: 1px solid;
  }
}
于 2013-08-14T20:09:37.477 回答