在样式。css中,我使用媒体查询,这两者都使用的变体:

/*--[ Normal CSS styles ]----------------------------------*/

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

    /*--[ Mobile styles go here]---------------------------*/
}

当我缩小窗口时,网站大小会调整到我在常规浏览器(Safari, Firefox)中想要的布局,然而,手机上根本不会显示移动布局。相反,我只看到默认的CSS。

有人能告诉我正确的方向吗?


当前回答

你唯一需要的解决方法是:

把所有的媒体查询放在。css文件的末尾

它起作用了,试试吧

其他回答

我也有同样的问题,原来我的媒体查询顺序是错误的。它们应该在CSS中从最宽到最小定义

@media屏幕必须位于css的末尾,这一点很重要

总是在一些单位中提到max-width和min-width,比如px或rem。这对我来说很好。如果我写它没有单位,只有数字值,浏览器不能读取媒体查询。例子: 这是错误的 @media only screen和(max-width:950) 和 这是对的 @media only screen (max-width:950px)

@media all and (max-width:320px)and(min-width:0px) {
  #container {
    width: 100%;
  }
  sty {
    height: 50%;
    width: 100%;
    text-align: center;
    margin: 0;
  }
}

.username {
  margin-bottom: 20px;
  margin-top: 10px;
}

对我来说,我用max-height代替了max-width。

如果那是你,去改变它!

    @media screen and (max-width: 350px) {    // Not max-height
        .letter{
            font-size:20px;
        }
    }