【问题标题】:Media Queries behaving differently for each Browser每个浏览器的媒体查询行为不同
【发布时间】:2017-09-10 07:32:15
【问题描述】:

我正在开发一个简单的机构网站,除了媒体查询外,一切都运行良好。我是这项技术的新手,所以我真的不知道发生了什么。

当我在 iPad 上打开折叠的引导菜单时出现我的问题,就像屏幕和更小屏幕一样,这取决于浏览器。

它在 Firefox 上运行良好,但在 Chrome 和 Safari 上存在一些问题,所以它让我相信我的代码可以正常工作,但我缺少浏览器兼容性的一些重要方面。

我希望导航栏菜单在中等大小的屏幕(仅适用于 Firefox)和黑色的移动屏幕时以灰色背景打开(Safari 有一个错误,它会打开整个菜单并将其削减一半)。

这是网站:flowersforpeaceproject.com

这里是代码:

body {
    margin: 0;
    padding: 0;
    font-family: 'Merriweather Sans', sans-serif;
}

/*NAVBAR*/

.navbar{
    border: 0;
    position: absolute;
    top: 0;
    z-index: 10;
    width: 100%;
}

.navbar .nav > li > a{
    color: #1E73BE;
}

.navbar-default{
    background-color: transparent;
}

nav .navbar-brand img{
    height: 220px;
    margin-right: 20px;
}

/*MEDIA QUERIES*/
@media screen and (max-width: 1000px) {
  .navbar-header {
      float: none;
  }
  .navbar-toggle {
      display: block;
  }
  .navbar-collapse {
      border-top: 1px solid transparent;
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
  }
  .navbar-fixed-top {
      top: 0;
      border-width: 0 0 1px;
  }
  .navbar-collapse.collapse {
      display: none!important;
  }
  .navbar-nav>li {
      float: none;
  }
  .navbar-nav>li>a {
      padding-top: 10px;
      padding-bottom: 10px;
  }
  .collapse.in{
      display:block !important;
  }

  /*MY CODE*/
  #bs-example-navbar-collapse-1 .navbar-right{
      background-color: rgb(50,50,50, 0.9);
      border-radius: 10px;
      max-width: 180px;
  }
}


@media screen and (max-width: 480px){
    nav .navbar-brand img{
        height: 120px;
        margin-right: 20px;
    }

    #bs-example-navbar-collapse-1 .navbar-right{
        border: 0;
        position: absolute;
        top: 10;
        left: 0;
        z-index: 10;
        width: 700px;
        margin-left: 20px;
        background-color: black;
        border-radius: 10px;

    }

}
/*END MEDIA*/

...

【问题讨论】:

    标签: html css twitter-bootstrap cross-browser media-queries


    【解决方案1】:

    有一个很好的资源可用于学习和使用媒体查询。 here

    • 由于这是一个基于浏览器的媒体查询错误,您可以通过为每个屏幕分辨率指定不同的 CSS 来轻松解决。 这是一个生成媒体查询的好工具。 Open Site.

    在您的代码中,您可以生成 css,例如针对不同的屏幕分辨率。

    @media screen and (max-width: 400px) {
        border: 0;
                position: absolute;
                top: 10;
                left: 0;
                z-index: 10;
                width: 700px;
                margin-left: 20px;
                background-color: black;
                border-radius: 10px;
    }
    
    @media screen and (min-width: 401px) and (max-width: 720px) {
        border: 0;
                position: absolute;
                top: 10;
                left: 0;
                z-index: 10;
                width: 700px;
                margin-left: 20px;
                background-color: black;
                border-radius: 10px;
    }
    
    @media screen and (min-width: 721px) and (max-width: 1280px) {
        border: 0;
                position: absolute;
                top: 10;
                left: 0;
                z-index: 10;
                width: 700px;
                margin-left: 20px;
                background-color: black;
                border-radius: 10px;
    }
    
    @media screen and (min-width: 1281px) and (max-width: 1440px) {
        border: 0;
                position: absolute;
                top: 10;
                left: 0;
                z-index: 10;
                width: 700px;
                margin-left: 20px;
                background-color: black;
                border-radius: 10px;
    }
    
    @media screen and (min-width: 1441px) and (max-width: 1920px) {
        border: 0;
                position: absolute;
                top: 10;
                left: 0;
                z-index: 10;
                width: 700px;
                margin-left: 20px;
                background-color: black;
                border-radius: 10px;
    }
    
    @media screen and (min-width: 1921px) {
        border: 0;
                position: absolute;
                top: 10;
                left: 0;
                z-index: 10;
                width: 700px;
                margin-left: 20px;
                background-color: black;
                border-radius: 10px;
    }
    

    【讨论】:

    • 我花了很长时间看它,它不是 CSS 的东西(除非我的 CSS 文件有错字,我没有找到)。出于某种原因,它在 Firefox 中完美运行,但在 Chrome 和 Safari 中却不行。我看过一些关于嵌套媒体查询的内容,但我的查询不是嵌套的。我确实在我的 HTML 上设置了视口元数据。
    猜你喜欢
    • 1970-01-01
    • 2016-06-01
    • 1970-01-01
    • 2014-04-09
    • 1970-01-01
    • 2023-04-02
    • 2014-12-08
    • 1970-01-01
    • 2014-10-01
    相关资源
    最近更新 更多