CSS中的媒体查询未按预期工作

时间:2015-09-28 10:24:51

标签: html css wordpress css3 media-queries

我需要在我的网站上显示两个不同的徽标,具体取决于设备宽度。 如果设备的屏幕尺寸是300px或小于它,我需要显示小徽标。

网站:http://www.geekdashboard.com/

Logo.png - > http://www.geekdashboard.com/wp-content/themes/geekdashboard/images/logo.png

logo-small.png - > http://www.geekdashboard.com/wp-content/themes/geekdashboard/images/logo-small.png

CSS:

.header-image .site-title > a {
    background: url(images/logo.png) no-repeat left;
    float: left;
    min-height: 90px;
    width: 425px;
}

和小宽度设备的CSS如下

  @media only screen and (max-width: 320px) {

.header-image .site-title > a {
    background: url(images/logo-small.png) no-repeat left!important;
    width: 300px!important;
}

}

此代码无法按预期工作。即使在屏幕尺寸小于300像素的设备上,我仍然可以看到logo.png 提前致谢

3 个答案:

答案 0 :(得分:1)

Specifying the media type should work fine.

@media only screen and (max-width: 320px) {
    .header-image .site-title > a {
     background: url(images/logo-small.png) no-repeat left !important;
     width: 300px !important;
     }
}

@media only screen and (min-width: 321px) {
    .header-image .site-title > a {
    background: url(images/logo.png) no-repeat left;
    float: left;
    min-height: 90px;
    width: 425px;
    }
}

答案 1 :(得分:1)

不确定但似乎您的网站上已启用缓存,并且您的CSS中未将“logo.png”更改为“logo-small.png” - http://imgur.com/shhDjYa

可能尝试清除缓存,它会对你有所帮助!

答案 2 :(得分:0)

试试这个?

@media (max-width: 320px) {
    .header-image .site-title > a {
     background: url(images/logo-small.png) no-repeat left !important;
     width: 300px !important;
     }
}
@media (min-width: 321px) and (max-width: 480px) {

    .header-image .site-title > a {
    background: url(images/logo.png) no-repeat left;
    float: left;
    min-height: 90px;
    width: 425px;
    }
}