简体   繁体   English

768px以下的媒体查询无法正常工作

[英]Media Query below 768px not working

I am writing a media query for a web-page and managed to write media queries for 768 and below. 我正在为网页编写媒体查询,并设法为768及以下版本编写媒体查询。 But it doesn't work properly. 但是它不能正常工作。 I want to capture the portrait views of most of the mobiles( iphone4, iphone5,iphone3,asus galaxy 7,samsung galaxy sII, samsung galaxy s3 ) which is 320px. 我想捕获320px的大多数手机(iphone4,iphone5,iphone3,华硕银河7,三星银河sII,三星银河s3)的纵向视图。 The webpage I created was working for 768px and above but not working for media query below 768px 我创建的网页适用于768px以上的像素,但不适用于768px以下的媒体查询

@media (min-width:481px) and (max-width:768px) {
        .navbar-brand{
    margin-left: 80px;

        }}

      @media (min-width: 768px){ 
           .navbar-brand{
    margin-left: 100px;

    }
         @media (min-width: 991px){ 
        .navbar-brand{
    margin-left: 150px;

        }}

Here in this example margin left property working very well on min-width: 768px and min-width:991px but not working on @media (min-width:481px) and (max-width:768px). 在此示例中,margin left属性在min-width:768px和min-width:991px上工作得很好,但在@media(min-width:481px)和(max-width:768px)上不起作用。

You are missing a curly bracket to close of your media query for min-width: 768px . 您没有关闭大括号min-width: 768px的大括号。 Here's the final code with formatting to more easily see it. 这是带有格式设置的最终代码,可以更轻松地查看它。

@media (min-width:481px) and (max-width:768px) {
    .navbar-brand {
        margin-left: 80px;
    }
}

@media (min-width: 768px) {
    .navbar-brand {
        margin-left: 100px;
    }
}

@media (min-width: 991px) {
    .navbar-brand{
        margin-left: 150px;
    }
}

For capturing screensizes that is 320px with a specific margin you can either remove (min-width:481px) and from your first media query if the same styling should apply or add a media query specific for that case: 为了捕获具有特定边距的320px (min-width:481px) and您可以删除(min-width:481px) and从第一个媒体查询中删除(min-width:481px) and如果应应用相同的样式)或添加针对该情况的媒体查询:

@media (max-width: 320px) {
    .classname {
        enter some code here
    }
}

Please take a look and confirm below media queries with updated code. 请查看并确认下面的媒体查询以及更新的代码。

      @media only screen and (min-width: 768px) { 
        .navbar-brand {
           margin-left: 100px;
         }
      }

      @media only screen (min-width: 481px) and (max-width:767px) {
        .navbar-brand {
           margin-left: 80px;
         }
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM